File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Render,set editor to JTable Cells Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Render,set editor to JTable Cells " Watch "Render,set editor to JTable Cells " New topic
Author

Render,set editor to JTable Cells

Arun Sanker
Ranch Hand

Joined: Mar 21, 2007
Posts: 44
Hi Guys,

Iam new to swing & had to make 2 Gui controls as follows:

[1]1st GUI Control
*******************

Its like a table having 4 columns.
The 1st column is a fixed column,the 2nd ,3rd & 4th column contains comboboxes(All cells in the columns).




[2]The 2nd GUI control
***********************

Its also a table having 2 columns.

The 1st row is a fixed row.The 1st column is a tree & in the second column,all cells is a combo box.

Also,when collapsing & expanding the tree in the first column,the 2nd column cells should not collapse or expand with it.



I have gone through the java tutorials & came to the idea that for realising these 2 Gui Controls,I have to use a JTable & render it,set corresponding "editor" to it, to get the required results.


Could any one give a hand on, how I can achieve these 2 GUi Controls.

Any sample examples would be great....

Thanks

[ April 24, 2007: Message edited by: kohinoor ]
[ April 25, 2007: Message edited by: kohinoor ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
The first component should be easy enough using a custom renderer that implements TableCellRenderer. Use a JComboBox as the render component and configure it in the getTableCellRendererComponent method. Make up an editor thay extends DefaultCellEditor and pass in a JComboBox to the constructor. Configure the editor in the getTableCellEditorComponent method. Add an ActionListener to the editor component (JComboBox) and call stopCellEditing in its actionPerformed method.
Since you will use this renderer in three of four columns you can set it for the three columns with tableColumnModel.getColumn(n).setCellRenderer(r).

For the second component you could use a TreeTable which is discussed in three articles, found here:
Creating TreeTables in Swing
Creating TreeTables: Part 2
The Swing HTML Parser.
If you are using j2se 1.5+ you will need to make a minor modification to get the code to compile — see Treetable events for suggestion.
If this doesn't suit your needs I would make up a custom component with the tree in a scrollPane on the left and the comboBoxes in a panel on the right. Trying to put these together in a JTable looks like a lot of frustration.
edit: formatting
[ April 25, 2007: Message edited by: Craig Wood ]
Arun Sanker
Ranch Hand

Joined: Mar 21, 2007
Posts: 44
Thanks Craig...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Render,set editor to JTable Cells