-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8357176: java.awt javadoc code examples still use Applet API #25278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👋 Welcome back prr! A progress list of the required criteria for merging this PR into |
@prrace This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 80 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
It seems the new screenshots could be improved by capturing them on a HiDPI (Retina) display, as the current images appear blurry. And to eliminate background elements in the corners, it might be better to capture screenshots of undecorated windows as was done in the old images. |
* gridbag.setConstraints(button, c); | ||
* add(button); | ||
* } | ||
* static void addButton(String name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* static void addButton(String name, | |
* private static void addButton(String name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok ...
* static void addButton(String name, | ||
* GridBagLayout gridbag, | ||
* GridBagConstraints c, | ||
* Frame frame) { | ||
* Button button = new Button(name); | ||
* gridbag.setConstraints(button, c); | ||
* frame.add(button); | ||
* } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The add
method should indented by 4 spaces to the right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adjusting
* public static void main(String[] args) throws Exception { | ||
* | ||
* setFont(new Font("SansSerif", Font.PLAIN, 14)); | ||
* setLayout(gridbag); | ||
* EventQueue.invokeAndWait(() -> { | ||
* Frame frame = new Frame("GridBagLayout"); | ||
* GridBagLayout gridbag = new GridBagLayout(); | ||
* GridBagConstraints c = new GridBagConstraints(); | ||
* frame.setLayout(gridbag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main
method should be indented by 4 spaces to the right, it's inside GridBagLayoutExample
class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will adjust
* right-to-left container. | ||
* | ||
* <div style="margin:0 auto;width:680px;text-align:center;font-weight:bold"> | ||
* <div style="margin:0 auto;width:850px;text-align:center;font-weight:bold"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to keep the width small as it was?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt it - unless you make the font really small, maybe?
If you look at how it is today you'll see the buttons are packed together using Motif L&F
https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/java/awt/GridBagLayout.html
BTW I tried a couple of times to upload javadoc to cr.openjdk.org so I could show the new rendered javadoc but uploads failed ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW I tried a couple of times to upload javadoc to cr.openjdk.org so I could show the new rendered javadoc but uploads failed ...
I experienced some issues with uploading files to cr.openjdk.org some time ago; recently it worked well, however, the login isn't instantaneous. I uploaded the updated javadoc for PassFailJFrame
yesterday.
Yeah, it would be helpful to look at the updated javadoc. If I have some time, I'll build updated javadoc and upload it…
* for (int i = 0; i < 5; i++) { | ||
* anim[i] = getImage(getDocumentBase(), | ||
* "images/anim"+i+".gif"); | ||
* anim[i] = tk.getImage("anim"+i+".gif"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* anim[i] = tk.getImage("anim"+i+".gif"); | |
* anim[i] = tk.getImage("anim" + i + ".gif"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The images would look better with square borders… which are left on Windows 10 only.
If it's possible to make the pixels on the rounded corners transparent or at least white, the images would look better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not feel like getting into manual touch up of these images. In some cases they are a massive improvement over what was there before regardless eg this is how FlowLayout looks today
https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/java/awt/doc-files/FlowLayout-1.gif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I absolutely agree, the new screenshots are of a better quality.
To make the screenshots look good on High DPI displays, we need several images (preferably at 100%, 150% and 200% as the most common scales) and use the If you just create a screenshot on (Retina at 200% scale), the screenshots will be too large and still blurry as browsers will still scale up the screenshots to the scale of the display because the If we agree to go this way, I can create screenshots on Windows 10 (which still uses square window borders) in different resolutions. |
Re-doing the images was necessary because they were obviously applets and extremely dated, so they are better (IMO) and good enough. I just figured out how to do the screen capture without the corners. macOS screen capture included a massive shadow that doubled the size. There's a trick (or two) I'll upload new images If you want to do more in a follow-up fix, that's fine, although I am not sure about Windows 10 .. as its already on the way out. |
* public static void main(String[] args) throws Exception { | ||
* | ||
* EventQueue.invokeAndWait(() -> { | ||
* Frame frame = new Frame("GridLayout"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
https://cr.openjdk.org/~prr/8357176/api/java.desktop/java/awt/MediaTracker.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still have some minor nits.
* public class BorderLayoutExample { | ||
* | ||
* public static void main(String[] args) throws Exception { | ||
* | ||
* EventQueue.invokeAndWait(() -> { | ||
* Frame frame = new Frame("BorderLayout"); | ||
* frame.setLayout(new BorderLayout()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* public class BorderLayoutExample { | |
* | |
* public static void main(String[] args) throws Exception { | |
* | |
* EventQueue.invokeAndWait(() -> { | |
* Frame frame = new Frame("BorderLayout"); | |
* frame.setLayout(new BorderLayout()); | |
* public class BorderLayoutExample { | |
* | |
* public static void main(String[] args) throws Exception { | |
* EventQueue.invokeAndWait(() -> { | |
* Frame frame = new Frame("BorderLayout"); | |
* frame.setLayout(new BorderLayout()); |
I suggest following the standard indentation of 4 spaces to align with the recommended Java code style and dropping the blank line inside the main
method.
Is there any particular reason for using invokeAndWait
instead of invokeLater
? Most Java UI tutorials use invokeLater
.
(In the tests, we have to use invokeAndWait
.)
* <hr><blockquote><pre> | ||
* import java.awt.*; | ||
* import java.applet.Applet; | ||
* <hr> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* <hr> |
Drop the horizontal line. It separates the code from the paragraph that introduces it.
* <hr> | ||
* {@snippet lang='java': | ||
* <pre> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* <hr> | |
* {@snippet lang='java': | |
* <pre> | |
* {@snippet lang='java': |
<pre>
is inside the sample code.
* public static void main(String[] args) throws Exception { | ||
* | ||
* EventQueue.invokeAndWait(() -> { | ||
* Frame frame = new Frame("GridLayout"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
* <hr><blockquote><pre> | ||
* import java.awt.*; | ||
* import java.applet.Applet; | ||
* <hr> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* <hr> |
I suggest dropping the horizontal line from all the sample code.
* import java.awt.GridBagLayout; | ||
* | ||
* public class GridBagEx1 extends Applet { | ||
* public class GridBagLayoutExample { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sample indents each code block by 4 spaces, which is good.
* public class GridLayoutExample { | ||
* | ||
* public static void main(String[] args) throws Exception { | ||
* | ||
* EventQueue.invokeAndWait(() -> { | ||
* Frame frame = new Frame("GridLayout"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's indent the code by 4 spaces.
I'm also for removing the blank line that starts the main
method.
* | ||
* <hr><blockquote><pre>{@code | ||
* import java.applet.Applet; | ||
* <hr> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* <hr> |
* import java.awt.*; | ||
* import java.applet.Applet; | ||
* <hr> | ||
* {@snippet lang='java': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* {@snippet lang='java': | |
* {@snippet lang='java': |
Not really an issue, however, other instances have just one space.
* public void stop() { | ||
* animator = null; | ||
* } | ||
* } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* } | |
* } |
Correct the indentation.
* <img src="doc-files/FlowLayout-1.gif" | ||
* <img src="doc-files/FlowLayout-1.png" | ||
* ALT="Graphic of Layout for Three Buttons" | ||
* style="margin: 7px 10px;"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd drop this style
attribute. It indents the image by 10 pixels to the right so that it doesn't align to the left edge of the surrounding text.
I see no value in increasing the vertical margins by 7px. Each paragraph has already 14px top/bottom margins.
* <img src="doc-files/BorderLayout-1.png" alt="Diagram of a window | ||
* demonstrating BorderLayout. Each section of the BorderLayout contains a | ||
* Button corresponding to its position in the layout, one of: North, West, | ||
* Center, East, or South." style="margin: 7px 10px;"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd drop this style
attribute, too.
I think I have addressed all the "nits" |
this reference to applet still exists. |
btw maybe it is better to present these layouts using swing(and its components)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me.
Sergey's comment hasn't been resolved: MediaTracker.java
still references applets in the code sample at line 148:
jdk/src/java.desktop/share/classes/java/awt/MediaTracker.java
Lines 147 to 150 in 42242c3
* // The background image fills the frame so we | |
* // don't need to clear the applet on repaints. | |
* // Just call the paint method. | |
* public void update(Graphics g) { |
oops. I missed what that comment was about |
This is in the AWT package so I think AWT components is better. |
But these layout classes are used for both awt and swing libraries. And since we modernize the example and drop outdated applets we may change them to jframe instead+jbutton, on mac the images will be the same as for awt. |
I really don't see that as being the right thing to do here. |
The goal of this change is to delete the usage of applet, but as a replacement the change uses the awt frame, while i think the right thing to use in our examples are "modern" swing components |
/integrate |
Going to push as commit 139a05d.
Your commit was automatically rebased without conflicts. |
Update the some code examples and accompanying images to no longer mention or display as applets.
Progress
Warnings
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25278/head:pull/25278
$ git checkout pull/25278
Update a local copy of the PR:
$ git checkout pull/25278
$ git pull https://git.openjdk.org/jdk.git pull/25278/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25278
View PR using the GUI difftool:
$ git pr show -t 25278
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25278.diff
Using Webrev
Link to Webrev Comment