File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JComboBox" Watch "JComboBox" New topic
Author

JComboBox

Matt Bell
Greenhorn

Joined: Oct 20, 2009
Posts: 5
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?



Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2226
    
    8
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

Joined: Oct 20, 2009
Posts: 5
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JComboBox