Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Editable JComboBox w. JDialogBox

 
Charles Van Damme
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Charles Van Damme
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic