This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable with JList  RSS feed

 
John Coleman
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.
 
Bill Liteplo
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!