-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
5.0
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
If your code explicitly sets the current metal theme to a class that does not derive from OceanTheme, and you add a MouseListener to a JComboBox, the MouseListener never gets any events.
I ran into this issue trying to add a JPopupMenu to my JComboBox. To do this I have to register a mouse listener to my JComboBox, so I know when to show the JPopupMenu.
My application was written before 1.5 and the OceanTheme was released, and it allows the user to change application color themes by changing the current MetalTheme.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the sample code.
If you comment out line 17, and comment in line 18, then the application behaves correctly.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected to see my application print events to standard out when the mouse enters/leaves the combobox, is pressed/released on the combobox, and when clicked on the combobox.
ACTUAL -
My program writes nothing to standard out, which indicates that my mouse listener is not receiving any events.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.metal.*;
public class Test
{
public static void main( String[] args )
{
System.out.println( System.getProperty( "java.vm.version" ) );
SwingUtilities.invokeLater( new Runnable()
{
public void run()
{
MetalTheme theme = new DefaultMetalTheme(); // Line = Not Works
//MeatlTheme theme = new OceanTheme(); // Line = Works
MetalLookAndFeel.setCurrentTheme( theme );
try
{
UIManager.setLookAndFeel( "javax.swing.plaf.metal.MetalLookAndFeel" );
}
catch( Exception e )
{
e.printStackTrace();
}
JFrame frame = new JFrame( "My Test" );
Object[] items = { "One", "Two", "Three", "Four" };
JComboBox jcb = new JComboBox( items );
jcb.addMouseListener( new MouseAdapter()
{
public void mouseEntered( MouseEvent e )
{ System.out.println( "mouseEntered()" ); }
public void mouseExited( MouseEvent e )
{ System.out.println( "mouseExited()" ); }
public void mouseClicked( MouseEvent e )
{ System.out.println( "mouseClicked()" ); }
public void mousePressed( MouseEvent e )
{ System.out.println( "mousePressed()" ); }
public void mouseReleased( MouseEvent e )
{ System.out.println( "mouseReleased()" ); }
} );
frame.getContentPane().setLayout( new FlowLayout() );
frame.getContentPane().add( jcb );
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
frame.pack();
frame.setVisible( true );
}
} );
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
My application allows users to change the color theme of the application, and it accomplishes this through a class that is derived from DefaultMetalTheme. Theoretically, I could change this class to extend OceanTheme instead of DefaultMetalTheme, but that will most likely be a whole bunch of work.
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
If your code explicitly sets the current metal theme to a class that does not derive from OceanTheme, and you add a MouseListener to a JComboBox, the MouseListener never gets any events.
I ran into this issue trying to add a JPopupMenu to my JComboBox. To do this I have to register a mouse listener to my JComboBox, so I know when to show the JPopupMenu.
My application was written before 1.5 and the OceanTheme was released, and it allows the user to change application color themes by changing the current MetalTheme.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the sample code.
If you comment out line 17, and comment in line 18, then the application behaves correctly.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected to see my application print events to standard out when the mouse enters/leaves the combobox, is pressed/released on the combobox, and when clicked on the combobox.
ACTUAL -
My program writes nothing to standard out, which indicates that my mouse listener is not receiving any events.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.metal.*;
public class Test
{
public static void main( String[] args )
{
System.out.println( System.getProperty( "java.vm.version" ) );
SwingUtilities.invokeLater( new Runnable()
{
public void run()
{
MetalTheme theme = new DefaultMetalTheme(); // Line = Not Works
//MeatlTheme theme = new OceanTheme(); // Line = Works
MetalLookAndFeel.setCurrentTheme( theme );
try
{
UIManager.setLookAndFeel( "javax.swing.plaf.metal.MetalLookAndFeel" );
}
catch( Exception e )
{
e.printStackTrace();
}
JFrame frame = new JFrame( "My Test" );
Object[] items = { "One", "Two", "Three", "Four" };
JComboBox jcb = new JComboBox( items );
jcb.addMouseListener( new MouseAdapter()
{
public void mouseEntered( MouseEvent e )
{ System.out.println( "mouseEntered()" ); }
public void mouseExited( MouseEvent e )
{ System.out.println( "mouseExited()" ); }
public void mouseClicked( MouseEvent e )
{ System.out.println( "mouseClicked()" ); }
public void mousePressed( MouseEvent e )
{ System.out.println( "mousePressed()" ); }
public void mouseReleased( MouseEvent e )
{ System.out.println( "mouseReleased()" ); }
} );
frame.getContentPane().setLayout( new FlowLayout() );
frame.getContentPane().add( jcb );
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
frame.pack();
frame.setVisible( true );
}
} );
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
My application allows users to change the color theme of the application, and it accomplishes this through a class that is derived from DefaultMetalTheme. Theoretically, I could change this class to extend OceanTheme instead of DefaultMetalTheme, but that will most likely be a whole bunch of work.