RFR: 8357176: java.awt javadoc code examples still use Applet API [v2]
Alexey Ivanov
aivanov at openjdk.org
Wed May 21 16:31:59 UTC 2025
On Tue, 20 May 2025 21:56:28 GMT, Phil Race <prr at openjdk.org> wrote:
>> src/java.desktop/share/classes/java/awt/GridLayout.java line 50:
>>
>>> 48: *
>>> 49: * EventQueue.invokeAndWait(() -> {
>>> 50: * Frame frame = new Frame("GridLayout");
>>
>> I would like to bring this to the discussion not necessarily suggesting any changes. I noticed that the example uses a "frame", while the description above refers to a "window" it might be worth unification. Also, regarding invokeAndWait: it’s not strictly necessary here since this is AWT but it does not break anything. However, I wonder if it’s worth discussing the use of invokeAndWait vs invokeLater. In tests, we usually prefer invokeAndWait because we need to wait for the action to complete, but in applications invokeLater should work fine.
>
> A Frame (the java class) creates a window (the desktop concept). I would not want to promote the java type Frame to mean the concept.
> Regarding invokeAndWait vs invokeLater, either is fine in this case and main has nothing else to do whilst waiting and is the safest default.
> I pondered whether to do either in this simple case, but we do generally these days recommend this pattern even for AWT as Swing classes may be used to implement AWT .. and if I did not I guarantee someone would have said I should use it ! Whether or not it matters in this case.
I'm in favour of using `invokeLater` (or `invokeAndWait`) even for AWT components.
AWT doesn't explicitly declares its threading model. It's safer to create UI on EDT either way—it'll work for both AWT and Swing.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25278#discussion_r2100689626
More information about the client-libs-dev
mailing list