Skip to content

Conversation

@alisenchung
Copy link
Contributor

@alisenchung alisenchung commented Jun 25, 2024

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

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Integration blocker

 ⚠️ Title mismatch between PR and JBS for issue JDK-7188058

Issue

  • JDK-7188058: Background of uneditable TextComponents doesn't change to disabled color (Bug - P3) ⚠️ Title mismatch between PR and JBS.

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19876/head:pull/19876
$ git checkout pull/19876

Update a local copy of the PR:
$ git checkout pull/19876
$ git pull https://git.openjdk.org/jdk.git pull/19876/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 19876

View PR using the GUI difftool:
$ git pr show -t 19876

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19876.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 25, 2024

👋 Welcome back achung! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@alisenchung alisenchung marked this pull request as draft June 25, 2024 04:05
@openjdk
Copy link

openjdk bot commented Jun 25, 2024

@alisenchung This change is no longer ready for integration - check the PR body for details.

@openjdk
Copy link

openjdk bot commented Jun 25, 2024

@alisenchung The following label will be automatically applied to this pull request:

  • client

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.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Jun 25, 2024
@alisenchung alisenchung marked this pull request as ready for review July 1, 2024 16:39
@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 1, 2024
@mlbridge
Copy link

mlbridge bot commented Jul 1, 2024

Webrevs

super.setEditable(b);
Color defaultBackground = UIManager.getColor("TextArea.background");
if (!backgroundSetByClientCode) {
setBackground(b ? defaultBackground : SystemColor.control, false);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Comment on lines +362 to +366
void setBackground(Color c, boolean setByClient) {
backgroundSetByClientCode = setByClient;
super.setBackground(c);
}

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

@honkar-jdk
Copy link
Contributor

honkar-jdk commented Jul 4, 2024

@alisenchung I missed noticing it earlier, since this is an AWT test a more appropriate location would be java/awt/TextComponent, currently it is in swing test folder.

@alisenchung
Copy link
Contributor Author

@honkar-jdk @DamonGuy i've moved the test to the awt folder, can you take a look?

Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 27, 2024
@Override
public synchronized void setEditable(boolean b) {
super.setEditable(b);
Color defaultBackground = UIManager.getColor("TextArea.background");
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Member

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.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Aug 6, 2024
@alisenchung
Copy link
Contributor Author

@prsadhuk @DamonGuy can you take a look at the latest changes?

Copy link
Contributor

@DamonGuy DamonGuy left a 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.

@alisenchung
Copy link
Contributor Author

@prsadhuk can you take another look?

@alisenchung alisenchung requested a review from prsadhuk August 22, 2024 21:20
@prsadhuk
Copy link
Contributor

Code change looks good now but for me testcase is passing even without the fix..
Also, since the testcase is just testing the background color, I think it can be made automated and even headless by using textfield/textarea rendering to BufferedImage

}

@Override
public synchronized void setEditable(boolean b) {
Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Contributor

@kumarabhi006 kumarabhi006 Aug 23, 2024

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.

Test_UI_On_StartUp
Test_UI_On_StartUp

Test_UI_After_Click_DisableText_Button
Test_UI_After_Clicking_Disable

Test_UI_After_Click_EnableText_Button
Test_UI_After_Click_Enable

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 20, 2024

@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!

@aivanov-jdk
Copy link
Member

Also, since the testcase is just testing the background color, I think it can be made automated and even headless by using textfield/textarea rendering to BufferedImage

AWT components cannot be created in headless environment.

}

void setBackground(Color c, boolean setByClient) {
backgroundSetByClientCode = setByClient;
Copy link
Member

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) {
Copy link
Member

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.

@aivanov-jdk
Copy link
Member

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?

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 21, 2024

@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
@bridgekeeper
Copy link

bridgekeeper bot commented Oct 31, 2024

@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!

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 31, 2024

@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!

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 31, 2024

@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!

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 28, 2024

@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 /open pull request command.

@bridgekeeper bridgekeeper bot closed this Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client client-libs-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

6 participants