🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java.gui
Article #11

Re: JComboBox and Selection on Keystroke !!!

#11
From: Stefan Kirchberg
Date: Thu, 12 Oct 2000 00:00
53 lines
2891 bytes
You add a mouselistener to a JComboBox by adding it to the editor.
JComboBox editor is by default JTextField. You have to get the editor of
the JComboBox and then use getText() method on the editor. Check out
this example using an inner class: 

class ComboKeyAdapter extends java.awt.event.KeyAdapter {
	private com.sun.java.swing.JComboBox _combobox;
	private com.sun.java.swing.JTextField _editor;

	public ComboKeyAdapter (JComboBox comboBox) {		
	_combobox = comboBox;
	_editor = (JTextField) 	_combobox.getEditor().getEditorComponent();
	_editor.addKeyListener(this);	
	}

	public void keyReleased(java.awt.event.KeyEvent keyEvent) {				
	
	char keyTyped;	
	keyTyped = keyEvent.getKeyChar();		
	String str = _editor.getText();


Somewhere in your code you should have the following:
ComboKeyAdapter combo_key = new ComboKeyAdapter(getJComboBox_lver());

Hope this helps you
Natalie



Thomas Fichtenbauer wrote:
> 
> I need some help.
> I want a JComboBox to work so, that when user writes characters to
> combo's
> editor, the selection list changes according to characters written in
> combo. Or it chooses automatically the selection correponding with
> written characters.
> 
> This works fine when the JComboBox is not editable, but when i set the
> JComboBox to editable it won't work
> 
> There is a interface KeySelectionManager which contains the method
> selectionForKey.
> when the combobox is not editable the this method is called but when the
> combobox is set to
> editable the method is not called any more. why??
> 
> Does anyone knows how to implement it?
> I tryed nearly everything now but it still wont work and its very
> important for me !!
> 
> Pleez help me and send any suggestions
Technical Details
Message-ID: <39E5AA3F.8A2CA41F@medat.de>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <39DD849D.A34A4358@xsoft.at>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,3a7a8a01792d49e8
X-Google-Attributes: gid111d45,public
X-Google-Thread: 113ae9,3a7a8a01792d49e8
X-Google-Attributes: gid113ae9,public
X-Google-Thread: 10fd6d,3a7a8a01792d49e8
X-Google-Attributes: gid10fd6d,public
X-Google-Thread: 10a146,3a7a8a01792d49e8
X-Google-Attributes: gid10a146,public
X-Google-Thread: f8eda,3a7a8a01792d49e8
X-Google-Attributes: gidf8eda,public
From: Stefan Kirchberg <sk@medat.de>
Subject: Re: JComboBox and Selection on Keystroke !!!
Date: 2000/10/12
Message-ID: <39E5AA3F.8A2CA41F@medat.de>
X-Deja-AN: 680541185
Content-Transfer-Encoding: 7bit
References: <39DD849D.A34A4358@xsoft.at>
X-Accept-Language: de, en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: usenet@euler.space.net
X-Trace: euler.space.net 971352604 18225 195.30.177.1 (12 Oct 2000 12:10:04 GMT)
Organization: Medat GmbH
Mime-Version: 1.0
NNTP-Posting-Date: 12 Oct 2000 12:10:04 GMT
Newsgroups: comp.lang.java.gui,borland.public.jbuilder.java.swing,borland.public.jbuilder.dbswing,comp.lang.java.help,comp.lang.java.programmer