-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.3.0
-
x86
-
windows_nt
Name: skT45625 Date: 08/22/2000
java version "1.3.0"
java(TM) 2 Runtime Environment, Standard Edition (builder 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
The following source code creates a button to change look and feel, and a menu
item in the menu bar to show a dialog containing a combo box.
Steps to reproduce the problem
==============================
(1) Run the following program
(2) Click on the "Change" button
(3) Show the "My Dialog" with the JMenuItem
(4) Close the dialog
(5) Click on the "Change" button once again
(6) Show the "My Dialog" with the JMenuItem
(7) When the dialog is open, press the down arrow key on the keyboard. The
program will give a ClassCastException
java.lang.ClassCastException: javax.swing.plaf.metal.MetalComboBoxUI
at
com.sun.java.swing.plaf.windows.WindowsComboBoxUI$DownAction.ActionPerformed(Win
dowComboBoxUI.java:154)
Note: The bug can be reproduced.
Source Code
===========
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TestComboBox extends JFrame implements ActionListener
{
private static final String METAL_CLASS_NAME
= "javax.swing.plaf.metal.MetalLookAndFeel";
private static final String WINDOWS_CLASS_NAME
= "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
private JMenuItem m_show;
private JButton m_button;
private boolean m_changed;
public TestComboBox()
{
JPanel panel = (JPanel) getContentPane();
panel.setLayout(new BorderLayout());
panel.add("South", m_button = new JButton("Change Look And
Feel"));
m_button.addActionListener(this);
JMenuBar bar = new JMenuBar();
JMenu menu = new JMenu("File");
m_show = new JMenuItem("show dialog");
m_show.addActionListener(this);
menu.add(m_show);
bar.add(menu);
getRootPane().setJMenuBar(bar);
setSize(new Dimension(100, 100));
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == m_show)
{
MyDialog dialog = new MyDialog(this);
dialog.setVisible(true);
} else if (source == m_button)
{
try
{
if (m_changed)
{
UIManager.setLookAndFeel(METAL_CLASS_NAME);
} else
{
UIManager.setLookAndFeel(WINDOWS_CLASS_NAME);
}
} catch (Exception ex)
{
ex.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(TestComboBox.this);
m_changed = !m_changed;
}
}
public static void main(String[] args)
{
TestComboBox tr = new TestComboBox();
tr.setVisible(true);
}
// Inner class
private class MyDialog extends JDialog
{
public MyDialog(JFrame frame)
{
super(frame, "My Dialog", true);
JPanel panel = (JPanel) getContentPane();
Object [] choices = {"0", "1", "2", "3", "4", "5"};
panel.add(new JComboBox(choices));
pack();
setSize(getPreferredSize());
}
}
}
Stack Trace
===========
java.lang.ClassCastException: javax.swing.plaf.metal.MetalComboBoxUI
at
com.sun.java.swing.plaf.windows.WindowsComboBoxUI$DownAction.ActionPerformed(Win
dowComboBoxUI.java:154)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1702)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2156)
at javax.swing.JComponent.processBindings(JComponent.java:2193)
at ...
(Review ID: 108769)
======================================================================
- duplicates
-
JDK-4329280 UIManager default table is not correct updated during a LAF change
-
- Resolved
-