Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JCombobox  RSS feed

 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JCombobox and i write for example 's', i want that when i entered 's', the Jcombobox must display ONLY the words that begin whith 's'.
I tried to do it. The editor must be enabled.
Can you write me code please ?
Thanks.
 
Ashish Gupta
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Can you write me code please ?

And you claim as SCJP and Sun Certified Web Component Developer in your signature!!!
 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of taking care of my certif. Help me please.
I tried it . here is my code:
I writed a class.
But i didn't understand it why it doesn't work.
class MyKeyAdapter extends KeyAdapter
{
public JComboBox jc;
public JTextField jt;
public Vector v = new Vector();
public MyKeyAdapter(JComboBox combobox)
{
this.jc = combobox;
jt = (JTextField)combobox.getEditor().getEditorComponent();
jt.addKeyListener(this);
}
public void keyTyped(KeyEvent e)
{
char ch = e.getKeyChar();
if (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch))
return;
int pos = jt.getCaretPosition();
String str = jt.getText();
for (int i = 0 ; i < jc.getItemCount(); i++)
{
String item =jc.getItemAt(i).toString();
if(item.startsWith(str))
{
System.out.println(item);
jt.setText(item);
jt.setCaretPosition(item.length());
jt.moveCaretPosition(pos) ;
break;
}
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!