-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
5.0
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.5.0_14"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03)
Java HotSpot(TM) Client VM (build 1.5.0_14-b03, mixed mode, sharing)
also seen on:
java version "1.6.0_04"
Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
When a separator is added to a JMenu with the addSeparator() method, there is an inordinate amount of whitespace added above and below the separator. If the menuitem background and foreground colors are customized, this problem becomes readily more apparent, as the large block of white around the separator makes the separator stand out in an unfavorable way.
I have only seen this with the WindowsLookAndFeel in java 1.5 and above:
In java 1.4.2, this problem does not seem to exist.
With other looks and feels (MetalLookAndFeel, MotifLookAndFeel), the problem is not as apparent (slightly on MetalLookAndFeel, but nowhere near as noticeable).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Create a JMenu and add some JMenuItems to it
2) Add one or more menu separators, using the addSeparator() method
3) Customize MenuItems' colors (e.g. "MenuItem.foreground" and/or "MenuItem.background" to some custom colors). This step isn't necessary, but does bring out the color contrast better
4) Force the look and feel to WindowsLookAndFeel
5) Surface the menu.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Separator between the menu items will be minimal (a few pixels tall)
ACTUAL -
Separator between menu items will be several pixes tall (maybe about 3x the size of the expected separator height). There is only one separator line, but above and below it is a good deal of whitespace.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.plaf.*;
public class SeparatorProblemTest extends JFrame {
public SeparatorProblemTest(String title) {
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Menu 1");
JMenuItem menuItem = new JMenuItem("item 1");
menu.add(menuItem);
menu.addSeparator(); // WindowsLNF adds whitespace in java 1.5+
menuItem = new JMenuItem("item 2");
menu.add(menuItem);
menu.add(new JSeparator()); // this seems ok for WindowsLNF in java 1.4+
menuItem = new JMenuItem("item 3");
menu.add(menuItem);
menuBar.add(menu);
this.setJMenuBar(menuBar);
this.setSize(400, 300);
this.setResizable(true);
this.show();
}
static public void main(String[] args) {
UIManager.put("MenuItem.foreground", new ColorUIResource(Color.BLUE));
UIManager.put("MenuItem.background", new ColorUIResource(Color.CYAN));
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception ex) {
ex.printStackTrace();
}
String version = System.getProperty("java.version");
SeparatorProblemTest x = new SeparatorProblemTest("Java version: " + version);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The only way I've been able to get around this so far is that instead of using:
JMenu.addSeparator()
I've been using
JMenu.add(new JSeparator());
===
The source code above demonstrates the difference in look of the two commands (in java 1.5+). I expected addSeparator() to create a look like adding a new JSeparator.
Release Regression From : 1.4.2_15
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
java version "1.5.0_14"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03)
Java HotSpot(TM) Client VM (build 1.5.0_14-b03, mixed mode, sharing)
also seen on:
java version "1.6.0_04"
Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
When a separator is added to a JMenu with the addSeparator() method, there is an inordinate amount of whitespace added above and below the separator. If the menuitem background and foreground colors are customized, this problem becomes readily more apparent, as the large block of white around the separator makes the separator stand out in an unfavorable way.
I have only seen this with the WindowsLookAndFeel in java 1.5 and above:
In java 1.4.2, this problem does not seem to exist.
With other looks and feels (MetalLookAndFeel, MotifLookAndFeel), the problem is not as apparent (slightly on MetalLookAndFeel, but nowhere near as noticeable).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Create a JMenu and add some JMenuItems to it
2) Add one or more menu separators, using the addSeparator() method
3) Customize MenuItems' colors (e.g. "MenuItem.foreground" and/or "MenuItem.background" to some custom colors). This step isn't necessary, but does bring out the color contrast better
4) Force the look and feel to WindowsLookAndFeel
5) Surface the menu.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Separator between the menu items will be minimal (a few pixels tall)
ACTUAL -
Separator between menu items will be several pixes tall (maybe about 3x the size of the expected separator height). There is only one separator line, but above and below it is a good deal of whitespace.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.plaf.*;
public class SeparatorProblemTest extends JFrame {
public SeparatorProblemTest(String title) {
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Menu 1");
JMenuItem menuItem = new JMenuItem("item 1");
menu.add(menuItem);
menu.addSeparator(); // WindowsLNF adds whitespace in java 1.5+
menuItem = new JMenuItem("item 2");
menu.add(menuItem);
menu.add(new JSeparator()); // this seems ok for WindowsLNF in java 1.4+
menuItem = new JMenuItem("item 3");
menu.add(menuItem);
menuBar.add(menu);
this.setJMenuBar(menuBar);
this.setSize(400, 300);
this.setResizable(true);
this.show();
}
static public void main(String[] args) {
UIManager.put("MenuItem.foreground", new ColorUIResource(Color.BLUE));
UIManager.put("MenuItem.background", new ColorUIResource(Color.CYAN));
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception ex) {
ex.printStackTrace();
}
String version = System.getProperty("java.version");
SeparatorProblemTest x = new SeparatorProblemTest("Java version: " + version);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The only way I've been able to get around this so far is that instead of using:
JMenu.addSeparator()
I've been using
JMenu.add(new JSeparator());
===
The source code above demonstrates the difference in look of the two commands (in java 1.5+). I expected addSeparator() to create a look like adding a new JSeparator.
Release Regression From : 1.4.2_15
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
- duplicates
-
JDK-6575395 WindowsPopupMenuSeparatorUI does not paint background correctly
- Open