-
Couldn't load subscription status.
- Fork 6.1k
7188058: Background of TextComponents are not changing colors to the default disabled color when set to uneditable #19876
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 achung! A progress list of the required criteria for merging this PR into |
|
@alisenchung This change is no longer ready for integration - check the PR body for details. |
|
@alisenchung The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
| super.setEditable(b); | ||
| Color defaultBackground = UIManager.getColor("TextArea.background"); | ||
| if (!backgroundSetByClientCode) { | ||
| setBackground(b ? defaultBackground : SystemColor.control, false); |
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 there a reason behind choosing SystemColor.control as the default TextComponent system color?
I see another option SystemColor.text - the description sounds more close to the background color of text 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.
the SystemColor.control comes from the docs on TextComponent.setEditable
* If the flag is set to {@code true}, this text component
* becomes user editable. If the flag is set to {@code false},
* the user cannot change the text of this text component.
* By default, non-editable text components have a background color
* of SystemColor.control. This default can be overridden by
* calling setBackground.
| void setBackground(Color c, boolean setByClient) { | ||
| backgroundSetByClientCode = setByClient; | ||
| super.setBackground(c); | ||
| } | ||
|
|
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.
Does this need a method need a javadoc comment block like the setBackground method before it or like any of the methods in the 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.
since this method isn't a public or protected method (it's package-private, so it can't be accessed by users) there's no need for a javadoc comment
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.
Right. OK I'll wait for you to move the test to the AWT directory then because I do agree, the components involved seem to be AWT rather than Swing ones.
|
@alisenchung I missed noticing it earlier, since this is an AWT test a more appropriate location would be |
|
@honkar-jdk @DamonGuy i've moved the test to the awt folder, can you take a look? |
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.
Changes look good.
| @Override | ||
| public synchronized void setEditable(boolean b) { | ||
| super.setEditable(b); | ||
| Color defaultBackground = UIManager.getColor("TextArea.background"); |
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 am not sure if it is ok to use swing "UIManager" class in awt
I guess long time back somebody maybe @prrace mentioned that we should avoid calling swing class from awt?
I see we use AttributeSet in TextComponent for accessibility usage but am not sure if we can use without restriction?
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 call is only to get the default background of TextArea. Is there another way to grab the default color without using UIManager?
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.
Yes, but as far I could see TextArea.background property is being set in
AquaLookAndFeel.java, MotifLookAndFeel.java, BasicLookAndFeel.java, XAWTLookAndFeel.java and WindowsLookAndFeel.java
and this L&F will not be set in AWT environment, if I am not wrong so you will either get garbage or wrong default color if you use UIManager.getColor..so I guess you need to use TextComponent.getBackground() which returns SystemColor.control if nothing is set
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've made the change to use TextComponent.getBackground() instead to get the correct background color
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.
AWT components must not depend on javax.swing.UIManager — pluggable Look and Feels and UIManager are features of Swing.
Some AWT components are implemented using lightweight components from Swing, in this case it's appropriate to use javax.swing packages but not in the common code — in the peers.
As far as I can see, JDK-7188058 references Linux and macOS only. AWT component on Mac use Swing components; not sure about Linux though.
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.
Updates since my last comment look good.
|
@prsadhuk can you take another look? |
|
Code change looks good now but for me testcase is passing even without the fix.. |
| } | ||
|
|
||
| @Override | ||
| public synchronized void setEditable(boolean b) { |
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.
setEditable method is overridden in both TextArea and TextField class and method implementation is same. Since both of them are inherited from TextComponent class, could we move the code to TextComponent's setEditable method and remove them from respective classes?
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 is a good suggestion.
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.
@ Ran the test on mac machine and I observed no changes with or without your fix. And the text on first textfield seems selected and due to that it is of different color. Is it possible to make them unselected at test start up, so that the background color can be verified for enabled and disabled case easily?
Attached the screenshot for test ui.
|
@alisenchung This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
AWT components cannot be created in headless environment. |
| } | ||
|
|
||
| void setBackground(Color c, boolean setByClient) { | ||
| backgroundSetByClientCode = setByClient; |
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.
Assigning the passed value to backgroundSetByClientCode does not make sense to me: the code in TextArea.setEditable already depends on the value of backgroundSetByClientCode, and the field shouldn't change as the result.
| } | ||
|
|
||
| @Override | ||
| public synchronized void setEditable(boolean b) { |
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 is a good suggestion.
|
Is it a bug? How do native text fields and areas behave on Linux and macOS? Does any of them change colours when it's switched into uneditable mode? AWT components should behave as native controls do. On Windows, uneditable text field and text area usually have a different background which corresponds to background of a dialog box. Is it the case on Linux and macOS? |
|
@alisenchung This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
3 similar comments
|
@alisenchung This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
@alisenchung This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
@alisenchung This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
@alisenchung This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |



Currently the bug described in the issue is that the colors of the TextComponents do not change when setting TextComponents to uneditable. The default uneditable color (SystemColor.control) happens to be the same as the default for the editable color for some L&Fs, so the fix may not be initially noticeable. However, the bug still exists where the the color is not being changed when changing between editable and uneditable. You can check by changing TextComponent.getBackground() code to return Color.GRAY on line 342 and you can see that TextComponents are not changing to a gray background when set to uneditable.
This fix adds a private setBackground method in TextComponent so that TextArea and TextField can change the background color to the correct color (SystemColor.control) when set uneditable by overriding the TextComponent setEditable. You can verify the fix by changing this color to Color.GRAY and verifying the backgrounds change to gray when the TextComponents are disabled.
Progress
Integration blocker
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19876/head:pull/19876$ git checkout pull/19876Update a local copy of the PR:
$ git checkout pull/19876$ git pull https://git.openjdk.org/jdk.git pull/19876/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 19876View PR using the GUI difftool:
$ git pr show -t 19876Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19876.diff
Using Webrev
Link to Webrev Comment