• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Obvious JCombobox in a JTable?

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm developing an application that uses a JComboBox rendered in a column of a JTable. I've been getting feedback from users that it wasn't obvious that the particular column was a combo box. When the table is first displayed the text in this column just looks like normal text entered into the cell. It's not until the user actually clicks on the cell does it become apperant that it's a combo box and they can make a different selection. The normal "triangle" to the right of the combobox text is not being displayed that would normally indicate a combo box.

What's the best way to indicate to the users visually that a cell is a combobox and allows selection?

Thanks,
Dave
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also use a JCombobox as the cell renderer, not only as the editor.

But make sure that those are two different instances, otherwise you will see some strange behaviour...
 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's what I'm doing currently:



So I'm setting both the renderer and editor as a JComboBox. Have I setup the renderer correctly? Functionally, everything works fine as is. I can click on the cell and a combobox appears with the two values (AM/PM). It's just when the table is fist displayed you can't tell that the time period column contains comboboxes to select either AM or PM.

The question is this: What's the best way to indicate visually to the user that a cell's value can be changed using the JComboBox? Some I've talked to have suggested using a column header icon or maybe changing the color of the column.

As an example:

Figure 1: No combo box indicator is displayed (unable to visually tell that the "Time Period" column is selectable using a combo box)


Figure 2: Combo box displayed when user clicks on the cell

Thanks,
Dave

[ March 23, 2006: Message edited by: David Irwin ]

[ March 23, 2006: Message edited by: David Irwin ]
[ March 23, 2006: Message edited by: David Irwin ]
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, other than set the cell editor to be a combo box, you need to set the cell renderer (view -- when/where users can see).
Here is a custom one that you can set for the "time period" column:

then


Good luck.

ps. To be just on the safe side, to prevent MyTableCellRenderer (now a JComboBox) to get too many items added, do "removeAllItems()" before "addItem(value)".
If the our renderer was a Label, text field, there is no such worry.

[ March 23, 2006: Message edited by: Ben Zung ]
[ March 23, 2006: Message edited by: Ben Zung ]
 
Liar, liar, pants on fire! refreshing plug:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic