On Tue, 29 Nov 2022 00:05:18 GMT, Harshitha Onkar <hon...@openjdk.org> wrote:
>> src/java.desktop/share/classes/javax/swing/plaf/metal/MetalBorders.java line >> 267: >> >>> 265: } >>> 266: >>> 267: AffineTransform at = null; >> >> Because we'd no longer be causing a `ClassCastException` from casting this >> to be a `Graphics2D` object, later down on line 311, if the `Graphics` >> object isn't a G2D type, then it will throw an NPE. I fear matrices, so I >> have no idea what the value of `getScaleX()` would be otherwise--replace it >> with zero if null? > > @SWinxy Thanks for catching it. That's right, but the scale factor cannot be > zero, it should probably be handled similar to `stkWidth` if **'at is null'** > (at is null when g is not an instance of Graphics2D). I'll need to check the > scale value to be used in this context. > > Something like below. > `at != null ? at.getScaleX() : 1;` Oh I see. Otherwise the thickness would be zero. I feeeeel like doing a large if-else on checking if g is a Graphics2D would end up being cleaner. I fiddled around and this is what the else branch would look like with the affine transform value being `1`: g.translate(x, y); g.setColor(background); // Draw the bulk of the border for (int i = 0; i < 5; i++) { g.drawRect(i, i, w - (i * 2), h - (i * 2)); } if (c instanceof JInternalFrame internalFrame && internalFrame.isResizable()) { // Draw the Long highlight lines g.setColor(highlight); g.drawLine(CORNER + 1, 2, w - CORNER, 2); //top g.drawLine(2, CORNER + 1, 2, h - CORNER); //left g.drawLine(w - 2, CORNER + 1, w - 2, h - CORNER); //right g.drawLine(CORNER + 1, h - 2, w - CORNER, h - 2); //bottom // Draw the Long shadow lines g.setColor(shadow); g.drawLine(CORNER, 1, w - CORNER - 1, 1); g.drawLine(1, CORNER, 1, h - CORNER - 1); g.drawLine(w - 3, CORNER, w - 3, h - CORNER - 1); g.drawLine(CORNER, h - 3, w - CORNER - 1, h - 3); } // restore previous transform g.translate(-x, -y); ------------- PR: https://git.openjdk.org/jdk/pull/11305