aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes focusListener wont work on JComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "focusListener wont work on JComboBox" Watch "focusListener wont work on JComboBox" New topic
Author

focusListener wont work on JComboBox

Tal Tal
Ranch Hand

Joined: Dec 10, 2003
Posts: 40
hi
how is that the focus listener work only once.
if i use the following code, then when i click on the editable combobox for the first time it will detect the focusGained Event, and it will also detect the focusLost event when i set the combobox out of focus,
but when i click on the combobox for the second time it wont work anymore
why is that?
thanks

R.Joe
Ranch Hand

Joined: Jun 16, 2004
Posts: 31
Hello,
this is a code which solve ur problem u have to use setenbaled false

code
JComboBox jc = new JComboBox();
jc.addItem("");
jc.addItem("1");
jc.addItem("2");
jc.addItem("3");
jc.addItem("4");
jc.setEditable(true);
jc.getEditor().getEditorComponent().addFocusListener(
new FocusAdapter()
{
public void focusLost(FocusEvent e)
{
jc.setEnabled(false);
System.out.println("out of focus");
}
public void focusGained(FocusEvent e)
{
System.out.println("in focus");
}
});
getContentPane().add(jc);
----
let me know weather it will solve ur prob or not
Ravi
Tal Tal
Ranch Hand

Joined: Dec 10, 2003
Posts: 40
i dont see why that would solve my problem.
the reason the focusListener dont work on my code is because i use
updateUI() on the combobox when the focusGained method is triggered.
if i'll remove the updateUI() from the listener my code would work fine.
the problem is that i must have the updateUI() where it is now, how can that be done?

thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: focusListener wont work on JComboBox
 
Similar Threads
FocusListner not working on JMenu
Focus issues with SWT Button
Issues on focus with composites and their child widgets
JComboBox and FocusListener
JTextField Listener