• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JCombobox

 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
}
}
}
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic