-
Bug
-
Resolution: Fixed
-
P4
-
8u20, 9, 10
-
b07
-
x86
-
os_x
FULL PRODUCT VERSION :
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Darwin mac21 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
When you set a Border on a JScrollBar using the Mac look and feel, the scrollbar appears to ignore the border and allows the scroll thumb to move through the border. For example, if you set a border that adds space on the right of a horizontal scroll bar, the width of the scroll bar is not affected by the border when run using the Mac look and feel, and so the scroll thumb can be dragged into the border. If you run the same example using the Metal look and feel, then the right hand edge of the scroll bar stops at the border.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The test code provided sets a custom border on the scroll bar that adds 150 pixels of transparent red colour to the right side of the scroll bar. If you run the example with the default Mac look and feel, you'll be able to drag the scroll thumb into the border:
java ScrollBarBorderTest
If you set the look and feel to Metal, then the scroll bar stops at the border:
java -Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel ScrollBarBorderTest
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Using the Mac look and feel I would expect the scroll bar to stop at the red area of border.
ACTUAL -
Using the Mac look and feel the scroll bar extends into the border.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class ScrollBarBorderTest {
// On macOS 10.12.6 using the Mac look and feel (com.apple.laf.AquaLookAndFeel)
// the scroll bar ignores the custom border and allows the scroll thumb to move
// beneath the border. Run with:
// java ScrollBarBorderTest
// If run using any other look and feel (e.g. Metal) then the right side of
// the scroll bar stops at the border as expected. Run with:
// java -Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel ScrollBarBorderTest
// Java version: 1.8.0_151
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
// create scroll bar
JScrollBar scrollBar = new JScrollBar(Scrollbar.HORIZONTAL);
scrollBar.setBorder(new CustomBorder());
// create panel
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(new EmptyBorder(20, 20, 20, 20));
panel.add(new JLabel(UIManager.getLookAndFeel().toString()));
panel.add(Box.createVerticalStrut(20));
panel.add(scrollBar);
// create frame
JFrame frame = new JFrame("ScrollBarBorderTest");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
});
}
// custom border
private static class CustomBorder implements Border {
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
g.setColor(new Color(255, 0, 0, 100));
g.fillRect(width - 150, y, width, height);
}
public Insets getBorderInsets(Component c) {return new Insets(0, 0, 0, 150);}
public boolean isBorderOpaque() {return true;}
}
}
---------- END SOURCE ----------
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Darwin mac21 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
When you set a Border on a JScrollBar using the Mac look and feel, the scrollbar appears to ignore the border and allows the scroll thumb to move through the border. For example, if you set a border that adds space on the right of a horizontal scroll bar, the width of the scroll bar is not affected by the border when run using the Mac look and feel, and so the scroll thumb can be dragged into the border. If you run the same example using the Metal look and feel, then the right hand edge of the scroll bar stops at the border.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The test code provided sets a custom border on the scroll bar that adds 150 pixels of transparent red colour to the right side of the scroll bar. If you run the example with the default Mac look and feel, you'll be able to drag the scroll thumb into the border:
java ScrollBarBorderTest
If you set the look and feel to Metal, then the scroll bar stops at the border:
java -Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel ScrollBarBorderTest
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Using the Mac look and feel I would expect the scroll bar to stop at the red area of border.
ACTUAL -
Using the Mac look and feel the scroll bar extends into the border.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class ScrollBarBorderTest {
// On macOS 10.12.6 using the Mac look and feel (com.apple.laf.AquaLookAndFeel)
// the scroll bar ignores the custom border and allows the scroll thumb to move
// beneath the border. Run with:
// java ScrollBarBorderTest
// If run using any other look and feel (e.g. Metal) then the right side of
// the scroll bar stops at the border as expected. Run with:
// java -Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel ScrollBarBorderTest
// Java version: 1.8.0_151
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
// create scroll bar
JScrollBar scrollBar = new JScrollBar(Scrollbar.HORIZONTAL);
scrollBar.setBorder(new CustomBorder());
// create panel
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(new EmptyBorder(20, 20, 20, 20));
panel.add(new JLabel(UIManager.getLookAndFeel().toString()));
panel.add(Box.createVerticalStrut(20));
panel.add(scrollBar);
// create frame
JFrame frame = new JFrame("ScrollBarBorderTest");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
});
}
// custom border
private static class CustomBorder implements Border {
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
g.setColor(new Color(255, 0, 0, 100));
g.fillRect(width - 150, y, width, height);
}
public Insets getBorderInsets(Component c) {return new Insets(0, 0, 0, 150);}
public boolean isBorderOpaque() {return true;}
}
}
---------- END SOURCE ----------