• 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
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Editable JComboBox w. JDialogBox

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ...
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic