• 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 ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

JTable with JList  RSS feed

Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I make a column in a JTable use a JList so that I can pick multiple values for the column in
each row?
My example is a JTable of users with name, user groups, email address, manager name and a check box to allow sending of email. Each user can be a member of 1:n user groups defined in another JTable.
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you saying that you want each cell in one column of a JTable to allow a choice from a set of data defined elsewhere?
Typically, you would use a JComboBox, rather than a JList, but you could do either.
Create a class extending TableCellEditor that returns a JComboBox (or JList) as the editor component. You will have to figure out how to grab the values from your other table at that point.
Set that TableCellEditor as the editor for that column of your JTable (table.setDefaultEditor). You may also want to create a TableCellRenderer class for when the cell is being displayed, but not edited (table.setDefaultRenderer).
The class that you use as the argument in these methods should be the same that you specify in getColumnClass of your TableModel.

For example:

or something like that. Hope this helps.
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
how do I do my own kindle-like thing - without amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!