🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.java.gui
2 messages
2 total messages Started by Thomas Fichtenbauer Fri, 06 Oct 2000 00:00
JComboBox and Selection on Keystroke !!!
#10
Author: Thomas Fichtenbauer
Date: Fri, 06 Oct 2000 00:00
21 lines
2021 bytes
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
Re: JComboBox and Selection on Keystroke !!!
#11
Author: 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads