This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

focusListener wont work on JComboBox

 
Tal Tal
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic