-
Bug
-
Resolution: Fixed
-
P4
-
1.2.2
-
beta
-
generic, x86
-
generic, windows_nt
Name: rlT66838 Date: 08/06/99
When the look and feel is switched to Metal, the buttons of a
JToolBar see their rollover property set to false. This property
is never restored when the look and feel is switched back to
Windows or Motif.
Actually the toolbar should not set rollover property to
false. If the Metal look and feel says "buttons in a toolbar
shall not rollover" then it should ignore this property and
behave _as if_ it were false. Otherwise it has to keep track of
what was the property value before it was switched so that it
can be restored when switching back to another look and feel !!!
This bug has been there since a long time, at least since
1.2.0, and is still there in 1.2.2. So I guess it's time I
report it.
The following example code demonstrates the problem. You will
need to find two gifs somewhere and specify the path to where
you have put them to make it work. Also note that buttons that
are not in toolbars can have rollover=true in the Metal look
and feel which makes the metal toolbar behavior even stranger.
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class ToolbarTest extends JPanel implements ActionListener
{
static final String iconDefName="default.gif";
static final String iconRollName="roll.gif";
private static Icon getIcon(String name)
{
return (Icon)((UIDefaults.LazyValue)LookAndFeel.makeIcon(
ToolbarTest.class, name)).createValue(null);
}
JButton button;
JComboBox lnf;
ToolbarTest()
{
setLayout(new BorderLayout());
Icon iconRoll = getIcon(iconRollName);
Icon iconDef = getIcon(iconDefName);
JToolBar toolbar = new JToolBar();
button = new JButton(iconDef);
button.setRequestFocusEnabled(false);
button.setMargin(new Insets(1,1,1,1));
button.setPressedIcon(iconRoll);
button.setRolloverIcon(iconRoll);
button.setRolloverEnabled(true);
toolbar.add(button);
add(toolbar, BorderLayout.NORTH);
JButton button2 = new JButton(iconDef);
button2.setRequestFocusEnabled(false);
button2.setMargin(new Insets(1,1,1,1));
button2.setPressedIcon(iconRoll);
button2.setRolloverIcon(iconRoll);
button2.setRolloverEnabled(true);
add(button2, BorderLayout.WEST);
UIManager.LookAndFeelInfo[] lnfs = UIManager.getInstalledLookAndFeels();
String lnfClasses[] = new String[lnfs.length];
for (int i = 0; i < lnfs.length; i++)
lnfClasses[i] = lnfs[i].getClassName();
lnf = new JComboBox(lnfClasses);
lnf.setSelectedItem(UIManager.getSystemLookAndFeelClassName());
lnf.addActionListener(this);
add(lnf, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent e)
{
String selectedlnf = (String)lnf.getSelectedItem();
try {
UIManager.setLookAndFeel(selectedlnf);
SwingUtilities.updateComponentTreeUI(this);
System.out.println(button);
} catch (Exception ee) {}
}
public static void main(String args[])
{
JFrame frame = new JFrame("Rollover property of button in toolbar");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
JOptionPane.setRootFrame(frame);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {}
frame.getContentPane().add(new ToolbarTest());
frame.pack();
frame.setSize(new Dimension(300,150));
frame.show();
}
}
(Review ID: 93614)
======================================================================
Name: krT82822 Date: 09/27/99
9/27/99 eval1127@eng -- already covered in #'s 4260485, 4268306, 4247996
The RollOverButton works fine in a normal JPanel but it doesn't in a JToolBar
import java.awt.*;
import javax.swing.*;
public class Frame1 extends JFrame {
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel2 = new JPanel();
JToolBar jToolBar1 = new JToolBar();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
FlowLayout flowLayout1 = new FlowLayout();
public Frame1() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Frame1 frame11 = new Frame1();
frame11.setSize(400,300);
frame11.setVisible(true);
}
/** initialize frame
*/
private void jbInit() throws Exception {
this.getContentPane().setLayout(borderLayout1);
jPanel2.setBackground(SystemColor.info);
jPanel2.setLayout(flowLayout1);
jButton1.setRolloverEnabled(true);
jButton1.setBackground(Color.white);
jButton1.setIcon(new ImageIcon("Index.gif"));
jButton1.setMargin(new Insets(0, 0, 0, 0));
jButton1.setRolloverIcon(new ImageIcon("IndexRollOver.gif"));
jButton2.setRolloverEnabled(true);
jButton2.setBackground(Color.white);
jButton2.setIcon(new ImageIcon("Glossar.gif"));
jButton2.setMargin(new Insets(0, 0, 0, 0));
jButton2.setRolloverIcon(new ImageIcon("GlossarRollOver.gif"));
jButton3.setRolloverEnabled(true);
jButton3.setBackground(Color.white);
jButton3.setIcon(new ImageIcon("Index.gif"));
jButton3.setMargin(new Insets(0, 0, 0, 0));
jButton3.setRolloverIcon(new ImageIcon("IndexRollOver.gif"));
jButton4.setRolloverEnabled(true);
jButton4.setBackground(Color.white);
jButton4.setToolTipText("glossary");
jButton4.setIcon(new ImageIcon("Glossar.gif"));
jButton4.setMargin(new Insets(0, 0, 0, 0));
jButton4.setRolloverIcon(new ImageIcon("GlossarRollOver.gif"));
this.getContentPane().setBackground(SystemColor.info);
jToolBar1.setBackground(SystemColor.info);
flowLayout1.setAlignment(FlowLayout.LEFT);
flowLayout1.setHgap(0);
flowLayout1.setVgap(0);
this.getContentPane().add(jPanel2, BorderLayout.SOUTH);
jPanel2.add(jButton3, null);
jPanel2.add(jButton4, null);
this.getContentPane().add(jToolBar1, BorderLayout.NORTH);
jToolBar1.add(jButton1, null);
jToolBar1.add(jButton2, null);
}
}
(Review ID: 95763)
======================================================================