RFR: 8279614: The left line of the TitledBorder is not painted on 150 scale factor [v12]

Alexey Ivanov aivanov at openjdk.java.net
Mon May 9 16:29:57 UTC 2022


On Fri, 6 May 2022 22:09:30 GMT, Alisen Chung <achung at openjdk.org> wrote:

>> Changed the drawing area to be increased by 0.5 on the left side to prevent clipping
>
> Alisen Chung has updated the pull request incrementally with three additional commits since the last revision:
> 
>  - changed error message for gap between highlight and shadow
>  - fixed coordinate checks
>  - fixed bottom edge border starting x value, updated test

Changes requested by aivanov (Reviewer).

src/java.desktop/share/classes/javax/swing/border/EtchedBorder.java line 31:

> 29: import java.awt.Graphics2D;
> 30: import java.awt.Insets;
> 31: import java.awt.Rectangle;

`Rectangle` is not used, please remove the import.

test/jdk/java/awt/TitledBorder/TitledBorderTest.java line 66:

> 64:     public static JPanel parentPanel;
> 65:     public static JPanel childPanel;
> 66:     public static BufferedImage buff;

The `buff` field is no longer used, it should be removed.

All the panels can be local variables, they're only used in `createAndShowGUI`.

test/jdk/java/awt/TitledBorder/TitledBorderTest.java line 69:

> 67:     public static Color highlight = Color.RED;
> 68:     public static Color shadow = Color.BLUE;
> 69:     public static boolean showFrame = false;

The `showFrame` field can be local variable in `main` as you pass it to `createAndShowGUI`.

Shall `createAndShowGUI` be renamed to `createGUI`? It doesn't always show GUI now.

test/jdk/java/awt/TitledBorder/TitledBorderTest.java line 144:

> 142:                 y, img, shadow, scaling);
> 143:         hBorderLoop(img.getWidth() - ((int) (Math.floor(scaling)+5*scaling)), img.getWidth(),
> 144:                 y, img, highlight, scaling);

According to your comment above, the check for horizontal should actually look the same as `checkVerticalBorder` but you change `x` rather than `y`.

The current code doesn't catch the case where border lines are not adjacent.

For the sake of simplicity, I'd add empty border on the right side of the panel:

            parentPanel.setBorder(BorderFactory.createEmptyBorder(0, i, 4, 4));

This makes sure the highlight colour is always followed by the background colour, thus you don't have to handle the case where the highlight colour is the last colour in the image.

test/jdk/java/awt/TitledBorder/TitledBorderTest.java line 152:

> 150:                 + thickness + " Scaling: " + scaling + " x: " + x);
> 151:         if (thickness > expected) throw new RuntimeException("Vertical Border drawn too thick. Thickness: "
> 152:                 + thickness + " Scaling: " + scaling + " x: " + x);

I guess `thickness != expected` is enough.

I'd print both `x` and `y` where the error is detected. On the other hand, it's usually clear where the error is when you look at the image.

test/jdk/java/awt/TitledBorder/TitledBorderTest.java line 169:

> 167:                             + " Scaling: " + scaling + " x: " + x);
> 168:                 } else {
> 169:                     continue;

`continue` statement is redundant because you can't get into another `if` block.

test/jdk/java/awt/TitledBorder/TitledBorderTest.java line 266:

> 264:         }
> 265:     }
> 266: }

It's recommended to have a blank line in the end of files.

-------------

PR: https://git.openjdk.java.net/jdk/pull/7449



More information about the client-libs-dev mailing list