This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I am wondering how can we develop the custom JComboBox like Gmail "Select All" component having a JCheckBox at the top, which does not come in the drop down menu, but is click-able.
Any idea(s) and/or working examples would be highly appreciated.
add a listener to the 'checkbox at the top', when clicked,
iterate all the checkboxes in the dropdown, setting their state accordingly
Mansoor Akhtar
Greenhorn
Joined: Jul 11, 2010
Posts: 12
posted
0
How to put only one 'CheckBox at the top' INSIDE the JComboBox ???
and the rest of the components shown in the drop down menu are not really chechboxes ..... they seem to be simple strings ...
Not going to be easy. For starters, the GMail check box you're talking about is a tristate component whereas JCheckBox has only two selection states, so you'd have to fist develop tristate functionality
If I were to target doing this, I would start with a JToggleButton or maybe a JButton, add tristate functionality (probably by extending DefaultButtonModel) and apply a custom icon wrapped around UIManager.getIcon(CheckBox.icon). The paintIcon implementation would query the button state and paint accordingly. A popup menu would house the selection conditions, and ActionListeners on the menu items would take care of the filtering to apply the selection status of the items in the list.