RFR: JDK-8290469: Add new positioning options to PassFailJFrame test framework [v4]
Phil Race
prr at openjdk.org
Fri Jul 29 20:15:09 UTC 2022
On Thu, 21 Jul 2022 00:27:04 GMT, Harshitha Onkar <honkar at openjdk.org> wrote:
>> Additional position setting (TOP_LEFT_CORNER) and a method to obtain bounds of test instruction frame are added to PassFailJFrame to handle positioning of multiple test frames.
>>
>> In scenarios where multiple test windows might be present, the test windows might overlap the instruction frame. In order to fix this TOP_LEFT_CORNER position option is added that positions the test instruction frame at top left corner with main test window below it.
>>
>> Additionally `getInstructionFrameBounds()` is added to obtain the position and dimensions of test instruction frame.
>
> Harshitha Onkar has updated the pull request incrementally with one additional commit since the last revision:
>
> added screen insets to account for taskbar position, doc changes
I can confirm that on Linux / Gnome with menu bar at the top and
toolbar on the left, that the requested location of 0,0 is not where
the window is placed but if called immediately both getLocation()
and getLocationOnScreen() may report back (0,0) leading to incorrect
positioning of the 2nd window.
Calling Toolkit.sync() isn't enough to ensure it is always correct.
In two runs of the same test code (my code below but without a sleep call) in one
case it then reports (0,0) and in another (74,27) - the actual location.
Calling isVisible() or isShowing() don't help.
The simplest thing that works every time for me is to add a short sleep()
to give time for everything to be processed. I didn't need the Robot.
It works both off and on the EDT.
Not 100% satisfactory as there really ought to be a better way but it seems
much more reliable than what we had and it keeps it easy to use.
I only tried this on Ubuntu 22.04 .. you'll need to test some other platforms
So just give that a try but do KEEP the insets calculations for the safest results.
import java.awt.*;
public class F {
public static void main(String[] args) throws Exception {
//doit();
EventQueue.invokeAndWait(F::doit);
}
public static void doit() {
Frame f1 = new Frame("Frame 1");
f1.setSize(300,200);
f1.setLocation(0,0);
f1.show();
Toolkit.getDefaultToolkit().sync();
try { Thread.sleep(500); } catch (InterruptedException e) {}
System.out.println("screen location ="+f1.getLocationOnScreen());
System.out.println("frame location ="+f1.getLocation());
System.out.println("frame size ="+f1.getSize());
int f2x = f1.getLocation().x+f1.getWidth();
int f2y = f1.getY();
System.out.println("desired frame 2 location = " + f2x + ", "+ f2y);
Frame f2 = new Frame("Frame 2");
f2.setSize(200,300);
f2.setLocation(f2x, f2y);
f2.show();
System.out.println("frame 2 location = " + f2.getLocation());
}
}
-------------
PR: https://git.openjdk.org/jdk/pull/9525
More information about the client-libs-dev
mailing list