• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComboBox

 
Matt Bell
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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?



 
Rob Camick
Ranch Hand
Posts: 2619
9
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic