-
Bug
-
Resolution: Duplicate
-
P5
-
None
-
6
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.5.0_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
5.1.2600
A DESCRIPTION OF THE PROBLEM :
Problem first noticed on 1.5.0_10; it may be older, but was not always there.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample under Windows (two icons named on.png and off.png must be supplied).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
There should be a toolbar consisting of a text field and two icons.
On the console, comments should report the size of the icons and of the buttons.
ACTUAL -
The text field runs all the way to the margin, and, although the console report gives the correct size for the icons, the buttons have negative sizes.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
// Two simple icons named on.png and off.png are necessary
// The program uses native look and feel, so will fail only when run under Windows
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
@SuppressWarnings("serial")
public final class RadioButtonBug extends JFrame {
final private JToolBar toolbar;
final private JTextField zero;
final private Icon on, off;
final private JRadioButton button1, button2, button3;
private RadioButtonBug() {
//init JFrame
setTitle("RadioButtonBug");
toolbar = new JToolBar();
toolbar.setFloatable(false);
add(toolbar, BorderLayout.NORTH);
zero = new JTextField(30);
toolbar.add(zero);
off = new ImageIcon(this.getClass().getResource("off.png"));
on = new ImageIcon(this.getClass().getResource("on.png"));
button1 = new JRadioButton(off);
button1.setSelectedIcon(on);
toolbar.add(button1);
button2 = new JRadioButton(off, true);
button2.setSelectedIcon(on);
toolbar.add(button2);
pack();
}
private void report() {
System.err.println("Icon 'on' is " + on.getIconWidth() + " by "
+ on.getIconHeight() + ',');
System.err.println("But button 'leftButton' is " + button1.getWidth()
+ " by " + button1.getHeight() + '.');
System.err.println("Icon 'off' is " + off.getIconWidth() + " by "
+ off.getIconHeight() + ',');
System.err.println("But button 'rightButton' is " + button2.getWidth()
+ " by " + button2.getHeight() + '.');
}
public static void main(String[] args) throws ClassNotFoundException,
IllegalAccessException, InstantiationException,
UnsupportedLookAndFeelException {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFrame.setDefaultLookAndFeelDecorated(true);
RadioButtonBug frame = new RadioButtonBug();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.report();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use JComponent.setBorder(); In the previous code, use: leftButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
java version "1.5.0_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
5.1.2600
A DESCRIPTION OF THE PROBLEM :
Problem first noticed on 1.5.0_10; it may be older, but was not always there.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample under Windows (two icons named on.png and off.png must be supplied).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
There should be a toolbar consisting of a text field and two icons.
On the console, comments should report the size of the icons and of the buttons.
ACTUAL -
The text field runs all the way to the margin, and, although the console report gives the correct size for the icons, the buttons have negative sizes.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
// Two simple icons named on.png and off.png are necessary
// The program uses native look and feel, so will fail only when run under Windows
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
@SuppressWarnings("serial")
public final class RadioButtonBug extends JFrame {
final private JToolBar toolbar;
final private JTextField zero;
final private Icon on, off;
final private JRadioButton button1, button2, button3;
private RadioButtonBug() {
//init JFrame
setTitle("RadioButtonBug");
toolbar = new JToolBar();
toolbar.setFloatable(false);
add(toolbar, BorderLayout.NORTH);
zero = new JTextField(30);
toolbar.add(zero);
off = new ImageIcon(this.getClass().getResource("off.png"));
on = new ImageIcon(this.getClass().getResource("on.png"));
button1 = new JRadioButton(off);
button1.setSelectedIcon(on);
toolbar.add(button1);
button2 = new JRadioButton(off, true);
button2.setSelectedIcon(on);
toolbar.add(button2);
pack();
}
private void report() {
System.err.println("Icon 'on' is " + on.getIconWidth() + " by "
+ on.getIconHeight() + ',');
System.err.println("But button 'leftButton' is " + button1.getWidth()
+ " by " + button1.getHeight() + '.');
System.err.println("Icon 'off' is " + off.getIconWidth() + " by "
+ off.getIconHeight() + ',');
System.err.println("But button 'rightButton' is " + button2.getWidth()
+ " by " + button2.getHeight() + '.');
}
public static void main(String[] args) throws ClassNotFoundException,
IllegalAccessException, InstantiationException,
UnsupportedLookAndFeelException {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFrame.setDefaultLookAndFeelDecorated(true);
RadioButtonBug frame = new RadioButtonBug();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.report();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use JComponent.setBorder(); In the previous code, use: leftButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
- duplicates
-
JDK-6496144 REGRESSION: JCheckBox doesn't show on JToolBar under Windows L&F
- Closed