On Thu, 5 Mar 2026 12:24:55 GMT, Prasanta Sadhukhan <[email protected]>
wrote:
>> test/jdk/java/awt/PrintJob/TestPrintNoException.java line 61:
>>
>>> 59: }
>>> 60:
>>> 61: private static Frame createUI() {
>>
>> This fits nicely into
>> [`splitUI`](https://cr.openjdk.org/~aivanov/PassFailJFrame/api/PassFailJFrame.Builder.html#splitUI(PassFailJFrame.PanelCreator))
>> use case.
>>
>> See
>> [`PrintLatinCJKTest.java`](https://github.com/openjdk/jdk/blob/master/test/jdk/java/awt/print/PrinterJob/PrintLatinCJKTest.java)
>> for an example, specifically:
>>
>> https://github.com/openjdk/jdk/blob/dfea6eb9f84142aaa3e51181ea345e8575729ea2/test/jdk/java/awt/print/PrinterJob/PrintLatinCJKTest.java#L117
>>
>> https://github.com/openjdk/jdk/blob/dfea6eb9f84142aaa3e51181ea345e8575729ea2/test/jdk/java/awt/print/PrinterJob/PrintLatinCJKTest.java#L68-L92
>
> splitUI doesn't work here as it expects a JComponent and getPrintJob expects
> a Frame
There's no requirement that a frame is visible, so you could use the following
code:
private static JComponent createUI() {
JButton b = new JButton("Print");
b.addActionListener((ae) -> {
Frame frame = new Frame();
try {
PrintJob pj = frame.getToolkit()
.getPrintJob(frame, "ResolutionTest", null);
PassFailJFrame.log("Printing code started.");
if (pj != null) {
pj.end();
}
} finally {
frame.dispose();
}
PassFailJFrame.log("Printing code finished.");
});
Box main = Box.createHorizontalBox();
main.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
main.add(Box.createHorizontalGlue());
main.add(b);
main.add(Box.createHorizontalGlue());
return main;
}
The UI looks cleaner, yet the code is less concise.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29874#discussion_r2890435254