• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

JComboBox inside JTable column

 
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

 
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
 
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
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!