Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combobox drop down

Status
Not open for further replies.

kohinoor2007

Programmer
Mar 21, 2007
69
0
0
DE
Hi guys,

Have a table ,in which Iam rendering a column to display as combobox while editing.
Iam doing it as follows.

// These are the combobox values
String[] values = new String[]{"item1", "item2", "item3"};
JComboBox comboBox = new JComboBox(values);
comboBox.setEditable(true);
sheetColumn.setCellEditor(new DefaultCellEditor(comboBox));

//sheetColumn is a column in my table.

Now when the user types in a key in the table cell,where a combobox is rendered into, want the combo drop down to open & show values correspong to the entered key.

As my combobox is an editable one,Know that I have to use the "SelectionForKey" function.

How will I get my combobox from the table,to call the "comboBox.SelectionForKey" from the listener as described below


Have added a listener as follows:
Would be nice if some one could show it with a code snippet from this point on..

table.addKeyListener(new KeyAdapter(){

public void keyTyped(KeyEvent e){
char c = e.getKeyChar();


})
}

Thanks...

 
I added the key listener to the JComboBox as follows.But its not entering the event handler...


final DefaultCellEditor test = (DefaultCellEditor)table.getColumnModel().getColumn(1).getCellEditor();
final JComboBox box = (JComboBox)test.getComponent();

box.addKeyListener(new KeyAdapter(){

public void keyTyped(KeyEvent e){
char c = e.getKeyChar();
box.selectWithKeyChar(c);
box.showPopup();
}
});
 
It worked when I did

combobox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter()

Thank God
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top