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

Phil Race prr at openjdk.java.net
Tue May 17 20:36:50 UTC 2022


On Tue, 10 May 2022 19:52:41 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 one additional commit since the last revision:
> 
>   renamed test, renamed some methods, updated error messages, updated test

Changes requested by prr (Reviewer).

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

> 130:     private void paintBorderShadow(Graphics g, Color c, int w, int h, int stkWidth) {
> 131:         g.setColor(c);
> 132:         g.drawLine((3*stkWidth/2), h-(3*stkWidth/2), (3*stkWidth/2), (3*stkWidth/2)); // left line

what do  you want to be the order of operations here
((3*stkWidth)/2) or (3*(stkWidth/2) ?
Make it clear with parens.

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

> 157:         int stkWidth = 1;
> 158:         if (g instanceof Graphics2D) {
> 159:             at = ((Graphics2D) g).getTransform();

We more usually write
Graphics2D g2d = (Graphics2D)g

then just use g2d instead of repeated casting.

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

> 162:             stkWidth = (int) Math.floor(Math.min(at.getScaleX(),at.getScaleY()));
> 163:             ((Graphics2D) g).setStroke(new BasicStroke((float) stkWidth));
> 164:         }

This reminds me .. did you try STROKE_PURE ? If so does it make any difference ?
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/RenderingHints.html#KEY_STROKE_CONTROL

src/java.desktop/share/classes/javax/swing/border/TitledBorder.java line 37:

> 35: import java.awt.geom.Path2D;
> 36: import java.beans.ConstructorProperties;
> 37: import java.beans.PropertyChangeListener;

Is removing an unused import the only change to TitledBorder ? I think you should revert this to make the change cleaner.

test/jdk/java/awt/TitledBorder/ScaledEtchedBorderTest.java line 9:

> 7:  * published by the Free Software Foundation.  Oracle designates this
> 8:  * particular file as subject to the "Classpath" exception as provided
> 9:  * by Oracle in the LICENSE file that accompanied this code.

This is wrong .. we do not put the classpath exception on tests.

test/jdk/java/awt/TitledBorder/ScaledEtchedBorderTest.java line 80:

> 78:         try {
> 79:             UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
> 80:         } catch (Exception e) {

Can we instead call
(https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/UIManager.html#getSystemLookAndFeelClassName())

Actually I'm not sure why only Win L&F is tested .. it is cross-platform and cross L&F code being changed

test/jdk/java/awt/TitledBorder/ScaledEtchedBorderTest.java line 237:

> 235:         } else {
> 236:             frame.dispose();
> 237:         }

That looks odd. I mean if you show the frame, how is it disposed ?

And more broadly ... why do you even create the frame if you never show it ?
And if you don't create the frame, this test can be headless, can't it ?

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

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



More information about the client-libs-dev mailing list