-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8279614: The left line of the TitledBorder is not painted on 150 scale factor #7449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
c368173
6e24762
b2e9240
4c8d5bf
f314462
c0b3189
47437d9
88c1b1a
6056faf
7b7732f
06ac18d
3ecaf58
75ec24d
9109b84
5d4854d
4dc1287
6c2efaf
a793582
89e64e9
a50bda0
6767407
e7b2706
b84cf51
e32e6c0
b17cdab
65200a2
61fc0ae
935ec43
cf91eb8
1d6ac07
8f71aba
adca6ef
24d7cee
325d09b
35e7d5a
317fe35
93f0b73
610d8f8
d4ad493
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| import java.awt.Insets; | ||
| import java.awt.Rectangle; | ||
| import java.awt.geom.Path2D; | ||
| import java.awt.geom.Rectangle2D; | ||
| import java.beans.ConstructorProperties; | ||
| import java.beans.PropertyChangeEvent; | ||
| import java.beans.PropertyChangeListener; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is removing an unused import the only change to TitledBorder ? I think you should revert this to make the change cleaner. |
||
|
|
@@ -350,10 +351,10 @@ public void paintBorder(Component c, Graphics g, int x, int y, int width, int he | |
| if (g2 instanceof Graphics2D) { | ||
| Graphics2D g2d = (Graphics2D) g2; | ||
| Path2D path = new Path2D.Float(); | ||
| path.append(new Rectangle(borderX, borderY, borderW, labelY - borderY), false); | ||
| path.append(new Rectangle(borderX, labelY, labelX - borderX - TEXT_SPACING, labelH), false); | ||
| path.append(new Rectangle(labelX + labelW + TEXT_SPACING, labelY, borderX - labelX + borderW - labelW - TEXT_SPACING, labelH), false); | ||
| path.append(new Rectangle(borderX, labelY + labelH, borderW, borderY - labelY + borderH - labelH), false); | ||
| path.append(new Rectangle2D.Float((float) borderX, borderY, borderW, labelY - borderY), false); | ||
|
||
| path.append(new Rectangle2D.Float((float) (borderX - 0.5), labelY, labelX - borderX - TEXT_SPACING, labelH), false); | ||
| path.append(new Rectangle2D.Float((float) (labelX + labelW + TEXT_SPACING - 0.5), labelY, borderX - labelX + borderW - labelW - TEXT_SPACING, labelH), false); | ||
| path.append(new Rectangle2D.Float((float) (borderX - 0.5), labelY + labelH, borderW, borderY - labelY + borderH - labelH), false); | ||
| g2d.clip(path); | ||
| } | ||
| border.paintBorder(c, g2, borderX, borderY, borderW, borderH); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import java.awt.BorderLayout; | ||
|
||
| import java.awt.Graphics2D; | ||
| import java.awt.Robot; | ||
| import java.awt.image.BufferedImage; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import javax.imageio.ImageIO; | ||
| import javax.swing.BorderFactory; | ||
| import javax.swing.JCheckBox; | ||
| import javax.swing.JFrame; | ||
| import javax.swing.JPanel; | ||
| import javax.swing.UIManager; | ||
| import javax.swing.UIManager.LookAndFeelInfo; | ||
| import javax.swing.UnsupportedLookAndFeelException; | ||
| import javax.swing.SwingUtilities; | ||
|
|
||
| /* | ||
| * @test | ||
| * @key headful | ||
| * @bug 8279614 | ||
| * @summary The left line of the TitledBorder is not painted on 150 scale factor | ||
| * @requires (os.family == "windows") | ||
| * @run main TitledBorderTest | ||
| */ | ||
| public class TitledBorderTest { | ||
|
|
||
| public static JFrame frame; | ||
| public static JPanel parentPanel; | ||
| public static JPanel childPanel; | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| LookAndFeelInfo laf = UIManager.getInstalledLookAndFeels()[3]; | ||
| System.out.println(laf); | ||
| SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf)); | ||
| SwingUtilities.invokeAndWait(() -> createAndShowGUI()); | ||
|
|
||
| Robot robot = new Robot(); | ||
|
|
||
| BufferedImage buff = new BufferedImage(frame.getWidth()*2, frame.getHeight()*2, | ||
| BufferedImage.TYPE_INT_ARGB); | ||
| Graphics2D graph = buff.createGraphics(); | ||
| graph.scale(1.5, 1.5); | ||
| frame.paint(graph); | ||
| graph.dispose(); | ||
|
|
||
| robot.waitForIdle(); | ||
| if (buff.getRGB(20,80) != -6250336) { | ||
| System.out.println("Color " + buff.getRGB(21, 80)); | ||
| saveImage(buff, "test.png"); | ||
| throw new RuntimeException("Border was clipped or overdrawn."); | ||
| } | ||
|
||
|
|
||
| frame.dispose(); | ||
| } | ||
|
|
||
| private static void createAndShowGUI() { | ||
| frame = new JFrame("Swing Test"); | ||
| frame.setSize(new java.awt.Dimension(300, 200)); | ||
| frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
|
|
||
| parentPanel = new JPanel(new BorderLayout()); | ||
| parentPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); | ||
|
|
||
| childPanel = new JPanel(new BorderLayout()); | ||
| childPanel.setBorder(BorderFactory.createTitledBorder("Title")); | ||
| childPanel.add(new JCheckBox(), BorderLayout.CENTER); | ||
|
|
||
| parentPanel.add(childPanel, BorderLayout.CENTER); | ||
|
|
||
| frame.getContentPane().add(parentPanel, BorderLayout.CENTER); | ||
|
|
||
| frame.pack(); | ||
| frame.setLocationRelativeTo(null); | ||
| frame.setVisible(true); | ||
| } | ||
|
|
||
| private static void saveImage(BufferedImage image, String filename) { | ||
| try { | ||
| ImageIO.write(image, "png", new File(filename)); | ||
| } catch (IOException e) { | ||
| // Don’t propagate the exception | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) { | ||
| try { | ||
| UIManager.setLookAndFeel(laf.getClassName()); | ||
| System.out.println(laf.getName()); | ||
| } catch (UnsupportedLookAndFeelException ignored){ | ||
| System.out.println("Unsupported LookAndFeel: " + laf.getClassName()); | ||
| } catch (ClassNotFoundException | InstantiationException | | ||
| IllegalAccessException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import isn't used. There are no other changes to this file but this added import.
In addition to it, you can also remove java.beans.PropertyChangeEvent from imports which is unused as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either revert the changes to
TitledBorderor remove the two unused imports:java.awt.geom.Rectangle2Dandjava.beans.PropertyChangeEvent.