[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Swing / AWT / SWT / JFace
 
RSS feed
 
New topic
Author

Swing JCombobox and JTable issue

binayakumar patel
Greenhorn

Joined: Jun 26, 2009
Messages: 27

Hi,

I am unable to add a Combo box in JTable 2nd column of each row with different value. Please help me.. I already try lots of time with many example but I man unable to change the ComboBox value in every row. Is it possible to rander a particular column with different component in every row ?
Rob Prime
Bartender

Joined: Oct 27, 2005
Messages: 8832

TableCellRenderer.getTableCellEditorComponent takes both the row and column numbers, so you can use that to your advantage. For example:
Of course you can use a Collection or List instead of an Object[], but the principle is the same.

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
binayakumar patel
Greenhorn

Joined: Jun 26, 2009
Messages: 27

Thanks Rob Prime. It is working fine.
yours solution helps me a lot.

I have one more doubt that , can not we Render the same cell with different component. Like the same column in first row with JCombo Box and the same column in next row with JTextField.

I have a Map, which I have to display in n-rows and 3-column table ... where for rew columns the value need to select from combobox and few need to enter. The number of rows we cant define... because it is dynamic.

Rob Prime
Bartender

Joined: Oct 27, 2005
Messages: 8832

Sure, just return a JTextField from that method.

The following class for instance uses a JComboBox, JTextField and a JCheckBox:

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
binayakumar patel
Greenhorn

Joined: Jun 26, 2009
Messages: 27

Thanks, It is working fine.

I face one more problem that, when i click on Cell for edit,then the scope is remains their till i will not give enter , in the case of JTextField.
Similarly in JComboBox the Scope is remain there till if I will not select any value from JComboBox.

Is there any way that it will lose its scope when i will click on any other cell.


Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Messages: 692

Instead of putting all the code in a custom editor, override the getCellEditor(...) method of JTable to return the appropriate editor for the row and column.
binayakumar patel
Greenhorn

Joined: Jun 26, 2009
Messages: 27

Hi Rob,

I can not understand / follow your suggestion can you please define it more clearly.

Rob Prime
Bartender

Joined: Oct 27, 2005
Messages: 8832

Rob Camick wrote:Instead of putting all the code in a custom editor, override the getCellEditor(...) method of JTable to return the appropriate editor for the row and column.

Uhm yeah, that would be better

Rob means this (which I used myself for a similar situation as well... why did I forget?):

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Swing / AWT / SWT / JFace
 
RSS feed
 
New topic
MyEclipse Enterprise Workbench