-
Type:
Bug
-
Resolution: Fixed
-
Priority:
P4
-
Affects Version/s: 1.2.0
-
Component/s: client-libs
-
swing1.1
-
sparc
-
solaris_2.6
Not able to change L&F when using Box.createGlue() with JMenuBar. Problem seen on both Solaris and Win NT. Used swing-1.0.1 release.
Steps to reproduce :
1. Comment the 'Code Section 1' only in the sample code and run the application.
2. Change L&F from the menu - Changing L&F works fine now.
3. Comment the 'Code Section 2' only in the sample code and run the application.
4. Change L&F from the menu - Changing L&F does not work now.
-- Sample Code --
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
public class TestBox extends JFrame implements ActionListener{
/*************************************** Bug Description ***************************************/
String[] strBugDesc = { "",
"",
"",
"",
"This TestCase tests the com.sun.java.swing.Box Component",
"**Problem** : Not able to change L&F when using Box.createGlue() with JMenuBar",
"Problem seen on both Solaris and Win NT",
"",
"Steps to reproduce :",
"1. Comment the 'Code Section 1' only in the code and run the application.",
"2. Changing L&F works fine now.",
"3. Comment the 'Code Section 2' only in the code and run the application.",
"4. Changing L&F does not work now. ",
"",
"",
"",
"",
""};
/*************************************** Bug Description ***************************************/
Container content;
JPanel panel;
JPanel menuPanel;
JButton bn;
/////// Code Section 1 ///////////
String[] data = {"File", "Edit", "View", "Go", "*", "Help"};
/////// Code Section 1 ///////////
/*
/////// Code Section 2 ///////////
String[] data = {"File", "Edit", "View", "Go", "Help"};
/////// Code Section 2 ///////////
*/
static String strMotif = "Motif";
static String motifClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
static char cMotif = 'o';
static String strWindows = "Windows";
static String windowsClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
static char cWindows = 'W';
static String strMetal = "Metal";
static String metalClassName = "com.sun.java.swing.plaf.metal.MetalLookAndFeel";
static char cMetal = 'M';
TestBox(String[] args) {
displayBugDesc();
content = getContentPane();
content.setLayout(new BorderLayout());
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event){
System.exit(0);
}
});
panel = new JPanel();
panel.setLayout(new BorderLayout(10, 10));
panel.add("North", getMyMenuBar());
panel.setPreferredSize(new Dimension(800, 100));
content.add("Center", panel);
content.add("South", new JButton("Dummy Button"));
pack();
show();
}
public JMenuBar getMyMenuBar() {
JMenuBar menubar;
JMenu menu;
JMenuItem menuitem;
menubar = GetLNFMenuBar();
for(int i = 0; i < data.length; i ++ ) {
if(data[i].equals("*"))
menubar.add(Box.createGlue());
else {
menu = new JMenu(data[i]);
menu.add(new JMenuItem(data[i]));
menubar.add(menu);
}
}
return menubar;
}
public void actionPerformed(ActionEvent e) {
String str = e.getActionCommand();
if(str.equals(metalClassName) || str.equals(windowsClassName) || str.equals(motifClassName)) {
changeLNF(str);
}
}
public void changeLNF(String str) {
System.out.println("Changing LNF to " + str);
try {
UIManager.setLookAndFeel(str);
SwingUtilities.updateComponentTreeUI(TestBox.this);
TestBox.this.pack();
}
catch (Exception exc) {
showErrorDialog(str);
}
}
public void showErrorDialog(String str) {
JLabel label = new JLabel("Could not load L&F : " + str);
JOptionPane.showMessageDialog(null, label, "Error", JOptionPane.ERROR_MESSAGE);
}
public JMenuBar GetLNFMenuBar() {
JMenuBar mbar = new JMenuBar();
JMenu m = new JMenu("Look and Feel");
m.setMnemonic('L');
ButtonGroup bg = new ButtonGroup();
JRadioButtonMenuItem mi;
mi = new JRadioButtonMenuItem(strMetal);
mi.addActionListener(this);
mi.setActionCommand(metalClassName);
mi.setMnemonic(cMetal);
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
mi.setSelected(true);
bg.add(mi);
changeLNF(metalClassName);
m.add(mi);
mi = new JRadioButtonMenuItem(strWindows);
mi.addActionListener(this);
mi.setActionCommand(windowsClassName);
mi.setMnemonic(cWindows);
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
bg.add(mi);
m.add(mi);
mi = new JRadioButtonMenuItem(strMotif);
mi.addActionListener(this);
mi.setActionCommand(motifClassName);
mi.setMnemonic(cMotif);
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, ActionEvent.ALT_MASK));
bg.add(mi);
m.add(mi);
mbar.add(m);
return mbar;
}
public void displayBugDesc() {
int n = strBugDesc.length;
System.out.println("/******************************* Bug Description and Comments *******************************/");
System.out.println();
for(int i = 0; i < n; i ++) {
System.out.println(strBugDesc[i]);
}
System.out.println();
System.out.println("/******************************* Bug Description and Comments *******************************/");
}
// Main funtion
public static void main(String[] args) {
TestBox frame = new TestBox(args);
}
}
-- Sample Code --
Steps to reproduce :
1. Comment the 'Code Section 1' only in the sample code and run the application.
2. Change L&F from the menu - Changing L&F works fine now.
3. Comment the 'Code Section 2' only in the sample code and run the application.
4. Change L&F from the menu - Changing L&F does not work now.
-- Sample Code --
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
public class TestBox extends JFrame implements ActionListener{
/*************************************** Bug Description ***************************************/
String[] strBugDesc = { "",
"",
"",
"",
"This TestCase tests the com.sun.java.swing.Box Component",
"**Problem** : Not able to change L&F when using Box.createGlue() with JMenuBar",
"Problem seen on both Solaris and Win NT",
"",
"Steps to reproduce :",
"1. Comment the 'Code Section 1' only in the code and run the application.",
"2. Changing L&F works fine now.",
"3. Comment the 'Code Section 2' only in the code and run the application.",
"4. Changing L&F does not work now. ",
"",
"",
"",
"",
""};
/*************************************** Bug Description ***************************************/
Container content;
JPanel panel;
JPanel menuPanel;
JButton bn;
/////// Code Section 1 ///////////
String[] data = {"File", "Edit", "View", "Go", "*", "Help"};
/////// Code Section 1 ///////////
/*
/////// Code Section 2 ///////////
String[] data = {"File", "Edit", "View", "Go", "Help"};
/////// Code Section 2 ///////////
*/
static String strMotif = "Motif";
static String motifClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
static char cMotif = 'o';
static String strWindows = "Windows";
static String windowsClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
static char cWindows = 'W';
static String strMetal = "Metal";
static String metalClassName = "com.sun.java.swing.plaf.metal.MetalLookAndFeel";
static char cMetal = 'M';
TestBox(String[] args) {
displayBugDesc();
content = getContentPane();
content.setLayout(new BorderLayout());
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event){
System.exit(0);
}
});
panel = new JPanel();
panel.setLayout(new BorderLayout(10, 10));
panel.add("North", getMyMenuBar());
panel.setPreferredSize(new Dimension(800, 100));
content.add("Center", panel);
content.add("South", new JButton("Dummy Button"));
pack();
show();
}
public JMenuBar getMyMenuBar() {
JMenuBar menubar;
JMenu menu;
JMenuItem menuitem;
menubar = GetLNFMenuBar();
for(int i = 0; i < data.length; i ++ ) {
if(data[i].equals("*"))
menubar.add(Box.createGlue());
else {
menu = new JMenu(data[i]);
menu.add(new JMenuItem(data[i]));
menubar.add(menu);
}
}
return menubar;
}
public void actionPerformed(ActionEvent e) {
String str = e.getActionCommand();
if(str.equals(metalClassName) || str.equals(windowsClassName) || str.equals(motifClassName)) {
changeLNF(str);
}
}
public void changeLNF(String str) {
System.out.println("Changing LNF to " + str);
try {
UIManager.setLookAndFeel(str);
SwingUtilities.updateComponentTreeUI(TestBox.this);
TestBox.this.pack();
}
catch (Exception exc) {
showErrorDialog(str);
}
}
public void showErrorDialog(String str) {
JLabel label = new JLabel("Could not load L&F : " + str);
JOptionPane.showMessageDialog(null, label, "Error", JOptionPane.ERROR_MESSAGE);
}
public JMenuBar GetLNFMenuBar() {
JMenuBar mbar = new JMenuBar();
JMenu m = new JMenu("Look and Feel");
m.setMnemonic('L');
ButtonGroup bg = new ButtonGroup();
JRadioButtonMenuItem mi;
mi = new JRadioButtonMenuItem(strMetal);
mi.addActionListener(this);
mi.setActionCommand(metalClassName);
mi.setMnemonic(cMetal);
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
mi.setSelected(true);
bg.add(mi);
changeLNF(metalClassName);
m.add(mi);
mi = new JRadioButtonMenuItem(strWindows);
mi.addActionListener(this);
mi.setActionCommand(windowsClassName);
mi.setMnemonic(cWindows);
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
bg.add(mi);
m.add(mi);
mi = new JRadioButtonMenuItem(strMotif);
mi.addActionListener(this);
mi.setActionCommand(motifClassName);
mi.setMnemonic(cMotif);
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, ActionEvent.ALT_MASK));
bg.add(mi);
m.add(mi);
mbar.add(m);
return mbar;
}
public void displayBugDesc() {
int n = strBugDesc.length;
System.out.println("/******************************* Bug Description and Comments *******************************/");
System.out.println();
for(int i = 0; i < n; i ++) {
System.out.println(strBugDesc[i]);
}
System.out.println();
System.out.println("/******************************* Bug Description and Comments *******************************/");
}
// Main funtion
public static void main(String[] args) {
TestBox frame = new TestBox(args);
}
}
-- Sample Code --