Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c368173
initial commit
Feb 8, 2022
6e24762
finished test
Feb 9, 2022
b2e9240
8279614: The left line of the TitledBorder is not painted on 150 scal…
Feb 11, 2022
4c8d5bf
changed carriage return
Feb 14, 2022
f314462
changed carriage return
Feb 14, 2022
c0b3189
trailing whitespace, add extra newline at eof
Feb 14, 2022
47437d9
reverted old change, swapped order of painting to prevent overdrawing
Mar 3, 2022
88c1b1a
typo
Mar 3, 2022
6056faf
adjusted pixels to check for border
Mar 3, 2022
7b7732f
added functions for drawing border, fixed translate
Mar 14, 2022
06ac18d
changed approach to render border without transforms
Mar 17, 2022
3ecaf58
updated test
Mar 17, 2022
75ec24d
fixed apostrophe in comment of saveImage
Mar 17, 2022
9109b84
scale stroke width at higher scalings
Mar 23, 2022
5d4854d
fixed 1.25 scaling overdraw, fixed calcs for right and bottom side bo…
Apr 7, 2022
4dc1287
forgot to change starting x value of bottom line
Apr 20, 2022
6c2efaf
updated test
May 2, 2022
a793582
saved translation values in EtchedBorder, updated test
May 5, 2022
89e64e9
fixed bottom edge border starting x value, updated test
May 6, 2022
a50bda0
fixed coordinate checks
May 6, 2022
6767407
changed error message for gap between highlight and shadow
May 6, 2022
e7b2706
made changes according to comments
May 9, 2022
b84cf51
made suggested changes
May 9, 2022
e32e6c0
renamed test, renamed some methods, updated error messages, updated test
May 10, 2022
b17cdab
made suggested changes
May 20, 2022
65200a2
reverted copyright year
May 20, 2022
61fc0ae
updated test
alisenchung May 25, 2022
935ec43
changed test to headless
alisenchung May 25, 2022
cf91eb8
updated test
alisenchung May 31, 2022
1d6ac07
don't reset transform if it contains a non-scale transformation
alisenchung Jun 3, 2022
8f71aba
skip transform is m01 or m10 is nonzero
alisenchung Jun 6, 2022
adca6ef
made suggested changes
alisenchung Jun 8, 2022
24d7cee
fixed spacing
alisenchung Jun 8, 2022
325d09b
fixed declarations
alisenchung Jun 8, 2022
35e7d5a
removed rendering hints, changed condition to reapply old transform
alisenchung Jun 8, 2022
317fe35
removed initialization
alisenchung Jun 10, 2022
93f0b73
changed initializations to null
alisenchung Jun 10, 2022
610d8f8
fix typo
alisenchung Jun 10, 2022
d4ad493
removed unused import
alisenchung Jun 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
Copy link
Member

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.

Copy link
Member

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 TitledBorder or remove the two unused imports: java.awt.geom.Rectangle2D and java.beans.PropertyChangeEvent.

import java.beans.ConstructorProperties;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the current coordinates do not work, is it because we calculate them in the wrong way or probably the insets are wrong?

Copy link
Contributor Author

@alisenchung alisenchung Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a rounding error when doing x.5 scalings causing the drawing area to be one pixel too small on the left side

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please check how it will work for the undecorated frame, if it will be fine then the problem is somehow related to the size of the insets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The undecorated frame has no problems

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrserb I've been trying to manually adjust the insets/variables to see what could be causing the issue, but only decreasing borderX by 1 seems to fix the issue. Could you clarify what you can gather from the undecorated frame working?

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);
Expand Down
97 changes: 97 additions & 0 deletions test/jdk/java/awt/TitledBorder/TitledBorderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import java.awt.BorderLayout;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent all this jcheck issue you can install the jcheck hook locally.

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.");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we draw directly to the buffered image using the scaled graphics to reproduce the bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, the test fails before the fix, and when inspecting the saved image it looks identical to the actual frame.


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);
}
}
}