dcsimg
FocusListener not working with JComboBox
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   mohamed_zafer
Posted On:   Thursday, December 27, 2001 09:17 PM

Hello There, I am using JComboBox and I have added FocusListener to it, but the listener fails to fire any event for focusgained or lost. I am using JDK1.3.1 on win2k any idea what could be wrong. Thanx Mohamed Zafer I am using the followinf code public class Jbrowser { public static void main(String[] args) { JFrame jf= new JFrame(); Container contentPane = jf.getContentPane(); contentPane.setLayout(new FlowLayout()); jf.addFocusListener(new ComponentFocusListener()); JComboBox jc = new JComboBox(); jc.addItem("CEO"); jc.addItem("COO");    More>>

Hello There,



I am using JComboBox and I have added FocusListener to it, but the listener fails to fire any event for focusgained or lost. I am using JDK1.3.1 on win2k any idea what could be wrong.



Thanx


Mohamed Zafer



I am using the followinf code



			
public class Jbrowser
{
public static void main(String[] args)
{
JFrame jf= new JFrame();
Container contentPane = jf.getContentPane();
contentPane.setLayout(new FlowLayout());
jf.addFocusListener(new ComponentFocusListener());

JComboBox jc = new JComboBox();
jc.addItem("CEO");
jc.addItem("COO");
jc.addFocusListener(new ComponentFocusListener());
JComboBox jcb = new JComboBox();
jcb.addItem("CTO");
jcb.addItem("CIO");
jcb.addFocusListener(new ComponentFocusListener());

JButton jb = new JButton("Check it out");
jb.addFocusListener(new ComponentFocusListener());
contentPane.add(jcb);
contentPane.add(jb);
contentPane.add(jc);
jf.setSize(600, 400);
jf.show();

}

static class ComponentFocusListener implements FocusListener
{
public void focusGained(FocusEvent e)
{
System.out.println("Focus gained in Form");
}

public void focusLost(FocusEvent e)
{
JComponent jc = (JComponent)e.getSource();
System.out.println("LOST :Name is"+jc.getName());

}
}
}
   <<Less
About | Sitemap | Contact