| Author |
Editable JComboBox w. JDialogBox
|
Charles Van Damme
Greenhorn
Joined: Feb 24, 2009
Posts: 12
|
|
Good day
I need a JComboBox or JList or JTable object where I can:
- select an item by the usual simple left click (default behaviour of JCombobox)
- get a dialog box by double clicking (or shift click or any else). This dialog box enables to:
- suppress an existing item
- add a space before an existing item, and then edit it (JTestField in a JDialogBox or JOptionPane)
- shift an item up or down in the list (Mutable items)
Anything I think I'm certainly not the only one to desire, is it ?
Could you give us some useful hints ? E.g.
- No JCombobox, rather JList because ...
- Need to use a data model, a CellRenderer, a CellEditor, an EventHandler ...
- regarding the event handler
- possible stumbling blocks
- URL of site to find code example in this direction
I think it would not succeed with a JComboBox because when attempting to double-click an item, as soon as the first click occured, the selection event handler operates and the box closes, leaving no time for a second click.
JList doesn't offer cell edition capabilities on the contrary of a JTable cell. That would not be an issue as the edition may occur in a JTestField of a JDialogBox or JOptionPane.
Thanks for any good intention ...
And thanks to Big Moose Saloon and their subscribers for the efficient tips that I got before ...
|
 |
Ranganathan Kaliyur Mannar
Bartender
Joined: Oct 16, 2003
Posts: 922
|
|
Yes, JList suits your situation better than JComboBox. You can also think of using a JTable with just one column - in this case, you can edit the data then and there.
As for JList, you can read the tutorial or check the api.
You should look to use a ListSelectionListener or MouseListener.
|
Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4166
|
|
I might go for an editable JComboBox, with a key binding (possibly Alt-Delete or Ctrl-Delete) added to remove the currently selected item. JComboBox being a composite component, the binding would likely have to be added to the WHEN_ANCESTOR_OF_FOCUSED_COMPONENT map.
edit Just re-read the OP.
- shift an item up or down in the list (Mutable items)
A single column JTable does sound more suitable for that. Reordering in a combo doesn't suggest any user-friendly approach.
|
luck, db
There are no new questions, but there may be new answers.
|
 |
Charles Van Damme
Greenhorn
Joined: Feb 24, 2009
Posts: 12
|
|
Thanks Ranganathan Kaliyur Mannar and Darryl Burke.
After thinking longly and looking attentively to all the methods of the JComboBox, JList and JTabel API's, a s o, I decided although to make a first a trial based on JComboBox.
Hence my next post "Preventing the unrolled list of a JComboBox to close".
Thanks again.
|
 |
 |
|
|
subject: Editable JComboBox w. JDialogBox
|
|
|