• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComboBox inside JTable column

 
mohana konakanchi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
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
extendsJComboBox
implementsTableCellRenderer
{
privatebooleanisSelected;
privatebooleanhasFocus;

public CustomTaskCellRenderer()
{
setEditable(true) ;
setLightWeightPopupEnabled(true);
setMaximumRowCount(5);
}
public Component getTableCellRendererComponent( JTable table,Object value, boolean isSelected, boolean hasFocus,
int row, int column )
{
this.isSelected = isSelected;
this.hasFocus = hasFocus;
setSelectedItem((String)value);
return this;
}
}
thanks in advance
mohana

 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
chantal
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chantal is right you need to have an editor. Look at the examples here for further info.
 
mohana konakanchi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx,
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
Mohana
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic