• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JComboBox

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,
I have a JComboBox in a JTable cell, that when you click on it or type on it, it lets you select / edit the contents.

I have a cell with JTextField works very similar and i use, a focus listener that uses textField.selectAll().
Both classes extend DefaultCellEditor.

I have tried to put a actionListener on the Combo box, and it gets called, and some code to try and make the selection highlighted, but it does nothing, it just gives an editable field, with the drop down options below... i need the editable field highlighted, any ideas?



 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well you need to do the same as you did for the JTextField. That is you need to add a FocusListener, not an ActionListner.

Except you need to add the focus listener to the editor, not the combo box. So you need to use the getEditor() method of the combo box and cast it to a JTextField.
 
Matt Bell
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help Rob.
I applied the focus listener to each child in the combo box, and this seemed to work on a click.

New problem, is navigating the table with the arrow keys. When I am over one of these combo box cells and start typing, it should jump into editable mode. Like a click.

Both a click and a keystroke take it into the Overridden getTableCellEditorComponent(), where the focus listeners are setup, but a click gains focus and a keystroke just shows the combobox(as if you could edit it (not highlighted) but you cannot edit until you click into it)

Basically need the KeyStroke to gain focus I think. Sorry if I havn't described it very well
Any ideas?
Thanks
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic