razo
asked on
Create a schedule
i need to create a schedule of appointments using java
the rows heading of the table signify the day while the columns heading are used for time
the user can also have the option of merging multiple rows for a given day to create an appointment that extend for multiple hours
i need this urgently
the rows heading of the table signify the day while the columns heading are used for time
the user can also have the option of merging multiple rows for a given day to create an appointment that extend for multiple hours
i need this urgently
ASKER
first it is not a homework
second i only need an outline like to use for the schedule; does JTable works for that?
and how i can i merge cells
second i only need an outline like to use for the schedule; does JTable works for that?
and how i can i merge cells
>> does JTable works for that?
Yeah, why not.
>> how i can i merge cells
You can't. But why should you?
You can change the background color to indicate an appointment that extends for multiple hours.
Yeah, why not.
>> how i can i merge cells
You can't. But why should you?
You can change the background color to indicate an appointment that extends for multiple hours.
Hello zzny, the java JTable has only a basic functinality. There are several other grid controls (see www.dundas.com or http://www.quest.com/jclass/index.asp) wich provide an enhance functionality. (Sorry they are not free)
>> Hello zzny
Are you talking to me?
>>the java JTable has only a basic functinality
Which is enough for what the user asks.
Look to Outlook's Calender: No merging of cells when indicating appointements of more than one hour.
Are you talking to me?
>>the java JTable has only a basic functinality
Which is enough for what the user asks.
Look to Outlook's Calender: No merging of cells when indicating appointements of more than one hour.
ASKER
i examined JTable yesterday and i couldn't find a way to put row headings
as for merging cells it is not necessary to merge but i want to give the user to be able to add an appointments thru the grid to extend for multiple hours...it is not only for view
as for merging cells it is not necessary to merge but i want to give the user to be able to add an appointments thru the grid to extend for multiple hours...it is not only for view
>> i want to give the user to be able to add an appointments thru the grid to extend for multiple hours
That can be done by selecting multiple cells (for one row/day)
>>i examined JTable yesterday and i couldn't find a way to put row headings
Did you put your table in a JScrollPane?
That can be done by selecting multiple cells (for one row/day)
>>i examined JTable yesterday and i couldn't find a way to put row headings
Did you put your table in a JScrollPane?
>> That can be done by selecting multiple cells.
Play around with this *very simple* example. Hopefully it gives you ideas.
/*
* TableDemo.java
*
*/
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
/**
*
*/
public class TableDemo extends javax.swing.JFrame {
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable theTable;
/** Creates new form TableDemo */
public TableDemo() {
initComponents();
initTable();
}
private void initTable() {
theTable.setModel(new MyOwnTableModel());
theTable.setCellSelectionE nabled(tru e);
}
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
theTable = new javax.swing.JTable();
addWindowListener(new java.awt.event.WindowAdapt er() {
public void windowClosing(java.awt.eve nt.WindowE vent evt) {
exitForm(evt);
}
});
jScrollPane1.setViewportVi ew(theTabl e);
getContentPane().add(jScro llPane1, java.awt.BorderLayout.CENT ER);
pack();
}
/** Exit the Application */
private void exitForm(java.awt.event.Wi ndowEvent evt) {
System.exit(0);
}
public static void main(String args[]) {
try {
UIManager.setLookAndFeel(U IManager.g etSystemLo okAndFeelC lassName() );
}
catch (Exception e) {
System.exit(0);
}
new TableDemo().show();
}
public class MyOwnTableModel extends DefaultTableModel {
final String[] columnNames = { "Day",
"08:00-08:15", "08:15-08:30",
"08:30-08:45", "08:45-09:00" };
private Object data[][] = {
{"Monday", " ", " ", " ", " "},
{"Tuesday", " ", " ", " ", " "},
{"Wednesday", " ", " ", " ", " "},
{"Thursday", " ", " ", " ", " "},
{"Friday", " ", " ", " ", " "},
{"Saturday", " ", " ", " ", " "},
{"Sunday", " ", " ", " ", " "},
};
public MyOwnTableModel() {
}
public boolean isCellEditable(int row, int col) { return false; }
public Class getColumnClass(int col) {
return super.getColumnClass(col);
}
public int getRowCount() { return 7; }
public int getColumnCount() { return 5; }
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
}
}
Play around with this *very simple* example. Hopefully it gives you ideas.
/*
* TableDemo.java
*
*/
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
/**
*
*/
public class TableDemo extends javax.swing.JFrame {
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable theTable;
/** Creates new form TableDemo */
public TableDemo() {
initComponents();
initTable();
}
private void initTable() {
theTable.setModel(new MyOwnTableModel());
theTable.setCellSelectionE
}
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
theTable = new javax.swing.JTable();
addWindowListener(new java.awt.event.WindowAdapt
public void windowClosing(java.awt.eve
exitForm(evt);
}
});
jScrollPane1.setViewportVi
getContentPane().add(jScro
pack();
}
/** Exit the Application */
private void exitForm(java.awt.event.Wi
System.exit(0);
}
public static void main(String args[]) {
try {
UIManager.setLookAndFeel(U
}
catch (Exception e) {
System.exit(0);
}
new TableDemo().show();
}
public class MyOwnTableModel extends DefaultTableModel {
final String[] columnNames = { "Day",
"08:00-08:15", "08:15-08:30",
"08:30-08:45", "08:45-09:00" };
private Object data[][] = {
{"Monday", " ", " ", " ", " "},
{"Tuesday", " ", " ", " ", " "},
{"Wednesday", " ", " ", " ", " "},
{"Thursday", " ", " ", " ", " "},
{"Friday", " ", " ", " ", " "},
{"Saturday", " ", " ", " ", " "},
{"Sunday", " ", " ", " ", " "},
};
public MyOwnTableModel() {
}
public boolean isCellEditable(int row, int col) { return false; }
public Class getColumnClass(int col) {
return super.getColumnClass(col);
}
public int getRowCount() { return 7; }
public int getColumnCount() { return 5; }
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
}
}
ASKER
ok that is exactly what i need but please i dont have time to research mutiple selection
please can u explain how can i do multiple selection and how can i allow the user to do that at run-time when adding data
thanks
please can u explain how can i do multiple selection and how can i allow the user to do that at run-time when adding data
thanks
Replace initTable() by this extended version.
And see the tracing when selecting multiple rows/columns.
private void initTable() {
theTable.setModel(new MyOwnTableModel());
theTable.setCellSelectionE nabled(tru e);
theTable.setSelectionMode( ListSelect ionModel.S INGLE_INTE RVAL_SELEC TION);
ListSelectionModel rowSM = theTable.getSelectionModel ();
rowSM.addListSelectionList ener(new ListSelectionListener() {
public void valueChanged(ListSelection Event e) {
//Ignore extra messages.
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel)e.getS ource();
if (lsm.isSelectionEmpty()) {
System.out.println("No rows are selected.");
} else {
int selectedRowFrom = lsm.getMinSelectionIndex() ;
int selectedRowTo = lsm.getMaxSelectionIndex() ;
if (selectedRowTo==selectedRo wFrom)
System.out.println("Row " + selectedRowFrom
+ " is now selected.");
else
System.out.println("Rows " + selectedRowFrom
+ " to " + selectedRowTo + " are now selected.");
}
}
});
ListSelectionModel colSM = theTable.getColumnModel(). getSelecti onModel();
colSM.addListSelectionList ener(new ListSelectionListener() {
public void valueChanged(ListSelection Event e) {
//Ignore extra messages.
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel)e.getS ource();
if (lsm.isSelectionEmpty()) {
System.out.println("No columns are selected.");
} else {
int selectedColFrom = lsm.getMinSelectionIndex() ;
int selectedColTo = lsm.getMaxSelectionIndex() ;
if (selectedColFrom==selected ColTo)
System.out.println("Column " + selectedColFrom
+ " is now selected.");
else
System.out.println("Column s " + selectedColFrom
+ " to " + selectedColTo + " are now selected.");
}
}
});
}
And see the tracing when selecting multiple rows/columns.
private void initTable() {
theTable.setModel(new MyOwnTableModel());
theTable.setCellSelectionE
theTable.setSelectionMode(
ListSelectionModel rowSM = theTable.getSelectionModel
rowSM.addListSelectionList
public void valueChanged(ListSelection
//Ignore extra messages.
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel)e.getS
if (lsm.isSelectionEmpty()) {
System.out.println("No rows are selected.");
} else {
int selectedRowFrom = lsm.getMinSelectionIndex()
int selectedRowTo = lsm.getMaxSelectionIndex()
if (selectedRowTo==selectedRo
System.out.println("Row " + selectedRowFrom
+ " is now selected.");
else
System.out.println("Rows " + selectedRowFrom
+ " to " + selectedRowTo + " are now selected.");
}
}
});
ListSelectionModel colSM = theTable.getColumnModel().
colSM.addListSelectionList
public void valueChanged(ListSelection
//Ignore extra messages.
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel)e.getS
if (lsm.isSelectionEmpty()) {
System.out.println("No columns are selected.");
} else {
int selectedColFrom = lsm.getMinSelectionIndex()
int selectedColTo = lsm.getMaxSelectionIndex()
if (selectedColFrom==selected
System.out.println("Column
+ " is now selected.");
else
System.out.println("Column
+ " to " + selectedColTo + " are now selected.");
}
}
});
}
ASKER
it is givin a syntax error on ListSelectionListener
do i have to import anything other what i imported at the beginning?
do i have to import anything other what i imported at the beginning?
Sorry. Add:
import javax.swing.event.*;
import javax.swing.event.*;
ASKER
ok one last thing there is a bug when i edit a cell i am not being able to select another cell
So, you mean:
When editing one cell, you're not able to select another cell.
What happens? Do you get an error?
When editing one cell, you're not able to select another cell.
What happens? Do you get an error?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok thanks look ill give u 100 more points if u could get me a way that when selecting 2 rows of the same column the lines between the two rows is removed
First of all, thanks for accepting. That keeps us answering your future questions too.
About your extra Q:
Do you mean this:
you select row 4 and row 7 (of say column 3),
then - I suppose - you press a button <delete>
then you want row 5 and 6 to be removed?
Is it something like that?
About your extra Q:
Do you mean this:
you select row 4 and row 7 (of say column 3),
then - I suppose - you press a button <delete>
then you want row 5 and 6 to be removed?
Is it something like that?
ASKER
hi
just wanted if u can do it or not???
i appreciate ur answer either way
thanks
just wanted if u can do it or not???
i appreciate ur answer either way
thanks
ASKER
no what i mean if the user selects rows 3 to 7 of a certain colum and he adds an appointment
then he sees the three columns having the same background color but with out having the dividing lines between them, the small line that distinguish a row from another row in the same column
then he sees the three columns having the same background color but with out having the dividing lines between them, the small line that distinguish a row from another row in the same column
Mmmm.
I know the JTable functions:
void setShowGrid(boolean showGrid)
Sets whether the table draws grid lines around cells.
void setShowHorizontalLines(boo lean showHorizontalLines)
Sets whether the table draws horizontal lines between cells.
void setShowVerticalLines(boole an showVerticalLines)
Sets whether the table draws vertical lines between cells.
but that's for the whole table, not for individual cells.
In coding everything is possible ;°)
So, there must be some way...
I know the JTable functions:
void setShowGrid(boolean showGrid)
Sets whether the table draws grid lines around cells.
void setShowHorizontalLines(boo
Sets whether the table draws horizontal lines between cells.
void setShowVerticalLines(boole
Sets whether the table draws vertical lines between cells.
but that's for the whole table, not for individual cells.
In coding everything is possible ;°)
So, there must be some way...
... but I can't find one. :(
Sorry.
Sorry.
ASKER
thanks for trying
look can u try to put in an editable cell a textbox that holds the data and whose height could be changed???
something like outlook calander
i really would appreciate it and dont worry about points if it hard and doable i can put more than 100 points
look can u try to put in an editable cell a textbox that holds the data and whose height could be changed???
something like outlook calander
i really would appreciate it and dont worry about points if it hard and doable i can put more than 100 points
Don't know if I understand...
>> a textbox that holds the data and whose height could be changed
Of no use. The cell height won't change because of containing a higher object.
If you want to change the height of a table row you can use JTable's setRowHeight() function:
public void setRowHeight(int row, int rowHeight)
Sets the height for row to rowHeight, revalidates, and repaints. The height of the cells in this row will be equal to the row height minus the row margin.
Parameters:
row - the row whose height is being changed
rowHeight - new row height, in pixels
Throws:
IllegalArgumentException - if rowHeight is less than 1
>>something like outlook calander
I don't see variable row heights in Outlook's calendar
???
>> i really would appreciate it and dont worry about points if it hard and doable i can put more than 100 points
That's OK. (I guess you mean you'll post another Q than?)
But first I have to know what exactly you want.
>> a textbox that holds the data and whose height could be changed
Of no use. The cell height won't change because of containing a higher object.
If you want to change the height of a table row you can use JTable's setRowHeight() function:
public void setRowHeight(int row, int rowHeight)
Sets the height for row to rowHeight, revalidates, and repaints. The height of the cells in this row will be equal to the row height minus the row margin.
Parameters:
row - the row whose height is being changed
rowHeight - new row height, in pixels
Throws:
IllegalArgumentException - if rowHeight is less than 1
>>something like outlook calander
I don't see variable row heights in Outlook's calendar
???
>> i really would appreciate it and dont worry about points if it hard and doable i can put more than 100 points
That's OK. (I guess you mean you'll post another Q than?)
But first I have to know what exactly you want.
ASKER
ok if u see outlook calandar when u add an appointment it shown as a text box in the the cell. this textbox can then be modified by increasing its length so that it extends over multiple cells....if we can do this than i don't need to change the cells at all
as for the points do i have to post another question? can i give you the extra points from here?
as for the points do i have to post another question? can i give you the extra points from here?
I see what you mean.
But that's not so easy.
First, you have to change the cursor when on a limit of an appointment (<> every horizontal line)
Secondly you have to change the background of the cells you move to while dragging.
I saw it quite easier:
1) Defining an appointment:
- Select a range of cells
- right-click and choose new appointment
- new appointment dialog comes up (with the from/to times according to the selected cells; can be changed of course)
- When closed possibly update the cells according to the changed time window
2) Changing the time window of an existing appointment (only not graphically)
- right-click the appointment and choose edit (or somehting)
- appointment dialog comes up again
- When closed possibly update the cells according to the changed time window
I admit: being able to change the time window graphically is cool, but is it really a must for you?
>>can i give you the extra points from here?
No you can't. Once a Q is closed the points can't be incremented. (btw. more than 500 points is also impossible)
So posting another Q is the only option.
But that's not so easy.
First, you have to change the cursor when on a limit of an appointment (<> every horizontal line)
Secondly you have to change the background of the cells you move to while dragging.
I saw it quite easier:
1) Defining an appointment:
- Select a range of cells
- right-click and choose new appointment
- new appointment dialog comes up (with the from/to times according to the selected cells; can be changed of course)
- When closed possibly update the cells according to the changed time window
2) Changing the time window of an existing appointment (only not graphically)
- right-click the appointment and choose edit (or somehting)
- appointment dialog comes up again
- When closed possibly update the cells according to the changed time window
I admit: being able to change the time window graphically is cool, but is it really a must for you?
>>can i give you the extra points from here?
No you can't. Once a Q is closed the points can't be incremented. (btw. more than 500 points is also impossible)
So posting another Q is the only option.
ASKER
ok i need it graphically it is important
i am ready to give u another 500 points if u can do it
but i have an idea if we add a textbox to the cell and then the user extends this textbox...not the cell, is that possible?
ok if u could do anything graphically can u let me know so that i post the new question
i am ready to give u another 500 points if u can do it
but i have an idea if we add a textbox to the cell and then the user extends this textbox...not the cell, is that possible?
ok if u could do anything graphically can u let me know so that i post the new question
>> if we add a textbox to the cell and then the user extends this textbox...not the cell, is that possible?
I'm afraid not. :(
You can define some text box as cell editor. But what then?
You can't update your table until you're done editing.
And in this case we want the table (cells) to follow the "editing". So... impossible I think.
If we want to do something like this, I think we will need to use a MouseListener and a MouseMotionListener on the table.
And then reacting (= adapting the selections of table cells) on mouse(drag)movements.
I'll see if I can (and find the time to) adapt the demo app with something like that.
I think it won't hurt to post a new Q.
Two or more experts always know more than one ;°)
(And if your Q isn't answered in your opinion, you can always make a request to delete it and refund the points)
I'm afraid not. :(
You can define some text box as cell editor. But what then?
You can't update your table until you're done editing.
And in this case we want the table (cells) to follow the "editing". So... impossible I think.
If we want to do something like this, I think we will need to use a MouseListener and a MouseMotionListener on the table.
And then reacting (= adapting the selections of table cells) on mouse(drag)movements.
I'll see if I can (and find the time to) adapt the demo app with something like that.
I think it won't hurt to post a new Q.
Two or more experts always know more than one ;°)
(And if your Q isn't answered in your opinion, you can always make a request to delete it and refund the points)
ASKER
ok ill post a new question
We can't do your homework for you...
Do you have a specific problem?