-
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
Changes from all commits
611bc7f
2a0cdbd
0b0f049
e83c29f
18f896b
ccf63c8
f8b9468
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 1995, 2024, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
|
|
@@ -359,6 +359,11 @@ public void setBackground(Color c) { | |
| super.setBackground(c); | ||
| } | ||
|
|
||
| void setBackground(Color c, boolean setByClient) { | ||
| backgroundSetByClientCode = setByClient; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assigning the passed value to |
||
| super.setBackground(c); | ||
| } | ||
|
|
||
|
Comment on lines
+362
to
+366
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need a method need a javadoc comment block like the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
| /** | ||
| * Gets the start position of the selected text in | ||
| * this text component. | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| /* | ||
| * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| import java.awt.Button; | ||
| import java.awt.Color; | ||
| import java.awt.FlowLayout; | ||
| import java.awt.Frame; | ||
| import java.awt.TextArea; | ||
| import java.awt.TextField; | ||
| import java.awt.event.ActionEvent; | ||
| import java.awt.event.ActionListener; | ||
|
|
||
| /* | ||
| * @test | ||
| * @bug 4258667 4405602 | ||
| * @summary Make sure TextComponents are grayed out when non-editable | ||
| * if the background color has not been set by client code. | ||
| * Make sure TextComponents are not grayed out when non-editable | ||
| * if the background color has been set by client code. | ||
| * @key headful | ||
| * @library /java/awt/regtesthelpers | ||
| * @build PassFailJFrame | ||
| * @run main/manual BackgroundTest | ||
| */ | ||
|
|
||
| public class BackgroundTest { | ||
| private static final String instructions = | ||
| """ | ||
| The test frame should have a blue background. | ||
| The first TextField and TextArea will be the default color. | ||
| On Windows and macOS, this is usually white. On Solaris, it will match | ||
| your environment settings. | ||
| The second TextField and TextArea will be green. | ||
|
|
||
| Press the DisableText button. | ||
|
|
||
| The first TextField and TextArea should change colors to the | ||
| default disabled color. On Windows, this is usually gray. | ||
| On Solaris, it will match your environment settings. If either | ||
| the TextField or the TextArea do not change colors as described, | ||
| the test FAILS. | ||
|
|
||
| The second TextField and TextArea should still be green. | ||
| If either of them are not green, the test FAILS. | ||
|
|
||
| Press the EnableText button (same button as before). | ||
|
|
||
| The first TextField and TextArea should return to their | ||
| original colors as described in the first paragraph. If they | ||
| do not, the test FAILS. | ||
|
|
||
| The second TextField and TextArea should still be green. | ||
| If either of them are not green, the test FAILS. | ||
|
|
||
| Otherwise, the test PASSES. | ||
| """; | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| PassFailJFrame.builder() | ||
| .instructions(instructions) | ||
| .rows((int) instructions.lines().count() + 1) | ||
| .columns(45) | ||
| .testUI(BackgroundTest::createUI) | ||
| .build() | ||
| .awaitAndCheck(); | ||
| } | ||
|
|
||
| public static Frame createUI() { | ||
| Frame f = new Frame("BackgroundTest"); | ||
|
|
||
| f.setBackground(Color.blue); | ||
| f.setLayout(new FlowLayout(FlowLayout.CENTER)); | ||
|
|
||
| TextField tf = new TextField(30); | ||
| TextArea ta = new TextArea(4, 30); | ||
| TextField setTf = new TextField(30); | ||
| TextArea setTa = new TextArea(4, 30); | ||
|
|
||
| Button enableButton = new Button("DisableText"); | ||
| enableButton.setBackground(Color.red); | ||
|
|
||
| tf.setText("Background not set - should be default"); | ||
| tf.setEditable(true); | ||
| f.add(tf); | ||
| ta.setText("Background not set - should be default"); | ||
| ta.setEditable(true); | ||
| f.add(ta); | ||
|
|
||
| setTf.setText("Background is set - should be Green"); | ||
| setTf.setBackground(Color.green); | ||
| setTf.setEditable(true); | ||
| f.add(setTf); | ||
| setTa.setText("Background is set - should be Green"); | ||
| setTa.setBackground(Color.green); | ||
| setTa.setEditable(true); | ||
| f.add(setTa); | ||
|
|
||
| enableButton.addActionListener(new ActionListener() { | ||
| @Override | ||
| public void actionPerformed(ActionEvent e) { | ||
| boolean currentlyEditable = tf.isEditable(); | ||
|
|
||
| tf.setEditable(!currentlyEditable); | ||
| ta.setEditable(!currentlyEditable); | ||
| setTf.setEditable(!currentlyEditable); | ||
| setTa.setEditable(!currentlyEditable); | ||
| enableButton.setLabel(currentlyEditable ? "EnableText" : "DisableText"); | ||
| } | ||
| }); | ||
|
|
||
| f.add(enableButton); | ||
|
|
||
| f.setSize(300, 300); | ||
| return f; | ||
| } | ||
| } |



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.
setEditablemethod is overridden in bothTextAreaandTextFieldclass and method implementation is same. Since both of them are inherited fromTextComponentclass, could we move the code toTextComponent's setEditablemethod 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.