-
Bug
-
Resolution: Fixed
-
P3
-
1.1.7, 1.2.0, 1.2.2, 1.3.0
-
beta
-
generic, x86
-
generic, windows_98, windows_nt
Name: vi73552 Date: 06/03/99
I can't seem to be able to listen to focusing (for example when press
the mouse) on a JComboBox. Other components such as JTextField work
fine. Can someone confirm if this is a swing bug (Swing 1.1.1-beta2).
The code being used follows:
<
((Component)lastField).addFocusListener( myFocusAdaptor);
>
<
class MyFocusAdaptor implements FocusListener
{
public void focusGained( FocusEvent e)
{
System.out.println( "In focusGained for " +
((Component)e.getSource()).getName());
}
public void focusLost( FocusEvent e)
{
}
}
>
The following is a complete demonstration. If you have an older
version of Swing (import com.sun.java.swing.*) then you should
be able to see that focusing used to work.
================================start TestCombo.java
//import com.sun.java.swing.*; REPLACED THIS LINE WITH NEXT TWO
import javax.swing.JComboBox;
import javax.swing.JTextField;
//
import java.awt.*;
import java.awt.event.*;
class TestCombo
extends Panel
implements FocusListener
{
public TestCombo()
{
setLayout( new GridLayout( 2,1));
JComboBox jc = new JComboBox();
jc.setName( "JComboBox");
((Component)jc).addFocusListener( this);
add( jc);
// MADE THE TEXT FIELD A SOURCE AS WELL SO WE CAN SEE ONE WORKING
JTextField tf = new JTextField();
tf.setName( "JTextField");
tf.addFocusListener( this);
add( tf);
}
public static void main( String arg[])
{
Frame jf = new Frame();
jf.setLayout( new GridLayout( 1,1));
jf.add( new TestCombo());
jf.setSize( 100,50);
jf.show();
}
public void focusGained( FocusEvent evt)
{
System.out.println( "Gained focus - " + ((Component)evt.getSource()).getName());
}
public void focusLost( FocusEvent evt)
{
System.out.println( "Lost focus - " + ((Component)evt.getSource()).getName());
}
}
================================end TestCombo.java
(Review ID: 83884)
======================================================================
Name: vi73552 Date: 06/04/99
JComboBox combo=new JComboBox();
combo.addFocusListener(this);
public void focusGained(FocusEvent e)
{
System.out.println("In focus gained ");
}
public void focusLost(FocusEvent e)
{
System.out.println("In focus Lost");
}
(Review ID: 83920)
======================================================================