Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
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 @@ -149,8 +149,8 @@ public static void applyInsets(Rectangle rect, Insets insets) {
if (insets != null) {
rect.x += insets.left;
rect.y += insets.top;
rect.width -= (insets.right + rect.x);
rect.height -= (insets.bottom + rect.y);
rect.width -= (insets.left + insets.right);
rect.height -= (insets.top + insets.bottom);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -41,6 +41,7 @@
import javax.swing.plaf.basic.BasicHTML;
import javax.swing.text.View;

import com.sun.java.swing.SwingUtilities3;
import sun.swing.MenuItemLayoutHelper;
import sun.swing.SwingUtilities2;

Expand Down Expand Up @@ -554,10 +555,10 @@ static Dimension getPreferredMenuItemSize(SynthContext context,

static void applyInsets(Rectangle rect, Insets insets, boolean leftToRight) {
if (insets != null) {
rect.x += (leftToRight ? insets.left : insets.right);
rect.y += insets.top;
rect.width -= (leftToRight ? insets.right : insets.left) + rect.x;
rect.height -= (insets.bottom + rect.y);
Insets newInsets = new Insets(insets.top, (leftToRight ? insets.left : insets.right),
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can eliminate the creation of a new object on each paint event? Since neither method is part of the public API, how about changing the signature of SwingUtilities3.applyInsets and removing the corresponding method in SynthGraphicsUtils?"

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. SwingUtilities3 can easily have two methods: applyInsets(Rectangle rect, Insets insets) as well as applyInsets(Rectangle rect, Insets insets, boolean leftToRight) where the former calls the latter with leftToRight = true.

insets.bottom, (leftToRight ? insets.right : insets.left));

SwingUtilities3.applyInsets(rect, newInsets);
}
}

Expand Down
52 changes: 52 additions & 0 deletions test/jdk/javax/swing/SwingUtilities/8365379/bug8365379.java
Copy link
Member

Choose a reason for hiding this comment

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

Since this test has nothing to do with the public API of javax.swing.SwingUtilities, it should reside in the folder structure that corresponds to com/sun/java/swing/SwingUtilities3.java, I propose test/jdk/com/sun/java/swing/SwingUtilities3/ApplyInsetsTest.java.

We no longer create directories for each test and give meaningful names to test files rather than bug####.java.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

import java.awt.Insets;
import java.awt.Rectangle;

import com.sun.java.swing.SwingUtilities3;

/*
* @test
* @bug 8365379
* @summary Verify LineBorder edges have the same width
* @modules java.desktop/com.sun.java.swing
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 verify it w/o using internals?

Copy link
Contributor Author

@Renjithkannath Renjithkannath Sep 11, 2025

Choose a reason for hiding this comment

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

As you are aware existing calculation will go wrong only for non zero X & Y. As far as my understanding existing calls passing 0,0 as X,Y. so I did not find any other way w/o using internals.

FYI : summary was wrong that I have corrected.

Let me know if you have any suggestions.

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 verify it w/o using internals?

This method is used menu rendering. All the current usages pass rectangles where x and y are zeros, so the existing code works correctly.

Yet the code in the method will produce wrong result if the x and y aren't equal to zero.

Since there are no other usages, it's impossible to reproduce the bug. Now that the method resides in SwingUtilities3, it's not localised its current usages, and if anyone uses the method, the result may be wrong.

This test is like a unit test that ensures the applyInsets method returns the correct and expected result with any parameters.

* @run main bug8365379
*/

public class bug8365379 {
public static void main(String[] args) {
Rectangle rect = new Rectangle(10, 20, 60, 60);
Insets insets = new Insets(5, 10, 15, 20);
Rectangle expected = new Rectangle(rect.x + insets.left,
rect.y + insets.top,
rect.width - (insets.left + insets.right),
rect.height - (insets.top + insets.bottom));

SwingUtilities3.applyInsets(rect, insets);
if (!rect.equals(expected)) {
throw new RuntimeException(("Test failed: expected " + expected + " but got " + rect));
}
System.out.println("Test passed.");
}
}