• Post Reply Bookmark Topic Watch Topic
  • New Topic

ComboBox in JTable

 
Venkata Ramana
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Created a JTable in that one column is a JComboBox. I want the drop down of combobox to be appeared when i press the down arrow key.(dropdown is coming when i click on it with mouse)
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
To do that you'll have to add a KeyAdapter to the JTable. Then in the keyPressed method of the KeyAdapter check the code of the key pressed like this:
If you ONLY want the arrow-down key to act on the comboBox you'd have to extend the JComboBox class and change that behaviour.

Hope that helps,
Terry
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramana,

Please re-register with a user name that follows the guidelines in the Official JavaRanch User Name Convention. Your user name is required to be in the format "First Name" + space + "Last Name".

Thanks,

-Nate
 
Chikoo V
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Terence Doyle:
HI,
To do that you'll have to add a KeyAdapter to the JTable. Then in the keyPressed method of the KeyAdapter check the code of the key pressed like this:
If you ONLY want the arrow-down key to act on the comboBox you'd have to extend the JComboBox class and change that behaviour.

Hope that helps,
Terry
 
Chikoo V
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Terence Doyle:
HI,
To do that you'll have to add a KeyAdapter to the JTable. Then in the keyPressed method of the KeyAdapter check the code of the key pressed like this:
If you ONLY want the arrow-down key to act on the comboBox you'd have to extend the JComboBox class and change that behaviour.

Hope that helps,
Terry


Hi
But this code doesnt seem to work for me.Have got the same problem but the piece of code that u have posted doent seem to work for me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!