Two Laptop Bag
The moose likes Swing / AWT / SWT and the fly likes JComboBox inside JTable column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JComboBox inside JTable column" Watch "JComboBox inside JTable column" New topic

JComboBox inside JTable column

mohana konakanchi
Ranch Hand

Joined: May 16, 2001
Posts: 67
I need to show a editable JComboBox inside one of the JTable columns. I did use TableCellRenderer by extending JComboBox.
I can see JComboBox in my JTable, But How I can update all the combo boxes in that column with what ever user enters in any combo box. I want functionly something like IE browser showing existing login ids from text box, when ever we want to login.
I add code below. Please correct me if I am in worng path.
Any other example also helpful.
class CustomTaskCellRenderer

public CustomTaskCellRenderer()
setEditable(true) ;
public Component getTableCellRendererComponent( JTable table,Object value, boolean isSelected, boolean hasFocus,
int row, int column )
this.isSelected = isSelected;
this.hasFocus = hasFocus;
return this;
thanks in advance

Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hi Mohana,
shouldn't you implement a JComboBox as TableCellEditor as well? (actually a JLabel as renderer will do it, the combobox is for editing)
attach an appropriate listener to the editor and update the data model. that should update the table. if you encounter any problems, post them.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Chantal is right you need to have an editor. Look at the examples here for further info.
mohana konakanchi
Ranch Hand

Joined: May 16, 2001
Posts: 67
I got the solution.
What you said is good solution. Examples link also help full.
I solved it different way. I just used DefaultCellEditor
and set it to table. Since all other columns are non editable,
this solution is cheep for me.
Since I am using only one combobox for all cells(in this case only one editable column) I could able to update it, when ever table is changed.
If you think it's a bad design, do not mind to reply
thanks once again
I agree. Here's the link:
subject: JComboBox inside JTable column
It's not a secret anymore!