• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Render,set editor to JTable Cells

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Craig...
 
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic