8377727: Ghost caret and focus appear in non‑editable text fields#30758
8377727: Ghost caret and focus appear in non‑editable text fields#30758azuev-java wants to merge 2 commits intoopenjdk:masterfrom
Conversation
…JDK 8u451+ Make caret color closer to the background color so it does appear as disabled caret.
|
👋 Welcome back kizune! A progress list of the required criteria for merging this PR into |
|
@azuev-java 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 240 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 |
|
@azuev-java 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
|
|
The total number of required reviews for this PR has been set to 2 based on the presence of this label: |
prrace
left a comment
There was a problem hiding this comment.
OK. I'm sure there'll be some opinions about whether it is now too low-contrast, but it does need to be distinguishable from the normal caret, otherwise people may think we didn't change anything.
| int red = (caretColor.getRed() + bg.getRed()) / 2; | ||
| int green = (caretColor.getGreen() + bg.getGreen()) / 2; | ||
| int blue = (caretColor.getBlue() + bg.getBlue()) / 2; | ||
| int alpha = 127; |
There was a problem hiding this comment.
Would it be enough to change the alpha component of the caret only?
There was a problem hiding this comment.
That might be simpler.
It occurred that the code above could cause an IAE since the Color constructor requires values to be in range.
If the caret is white and the bg is say rgb(2, 2,2) then you'll pass 256 and get an exception.
It needs to be clamped.
There are also methods on java.awt.Color
Color.darker()
and
Color.brighter()
which could be used, but you'd first need to examine the caret color and probably the background too, to know which one is appropriate.
ie for a light bg with a dark caret, you'll want to use brighter() to reduce the contrast.
And vice versa.
There was a problem hiding this comment.
If the caret is white and the bg is say rgb(2, 2,2) then you'll pass 256
No, i will not. The white is rgb(255, 255, 255) and bg is rgb(2, 2, 2) then i will pass rgb ((2 + 255) / 2, (2 + 255) / 2, (2 + 255) /2) which is rgb(128, 128, 128) which is gray - perfectly fits the purpose of the fix.
There was a problem hiding this comment.
Would it be enough to change the alpha component of the caret only?
Not sure it will work good on all color combinations so i did both added alpha value of 50% and brought color half way to the background.
There was a problem hiding this comment.
If the caret is white and the bg is say rgb(2, 2,2) then you'll pass 256
No, i will not. The white is rgb(255, 255, 255) and bg is rgb(2, 2, 2) then i will pass rgb ((2 + 255) / 2, (2 + 255) / 2, (2 + 255) /2) which is rgb(128, 128, 128) which is gray - perfectly fits the purpose of the fix.
You're right. I mis-read the parens.
|
I see an NPE when I focus a disabled text field with the |
hmm. That's clearly a problem. And surprising. The existing code doesn't have any obvious protection against null. |
I guess this means that the current graphics color is the fall back .. so if there's no caret color you need to use the current graphics color instead. |
Adding protection from null caret color and null background color (just in case). |
Which happens how? |
| if (bg == null) { | ||
| g.setColor(caretColor); |
There was a problem hiding this comment.
Does it make sense to add alpha to the caret if background color is null?
There was a problem hiding this comment.
This is a fallback which in theory should never happen because according to documentation it is impossible to set caret color to null, documentation for setCaretColor says:
Setting to null effectively restores the default color.
so i would leave it as is and instead looked at the Nimbus LaF to see why does it return null caret color for the disabled caret. Using the foreground color is a workaround to repeat the current behavior, not a proper solution. It might backfire on custom text component where user paints with some weird color something between text draw and caret painting.
|
/integrate |
|
Going to push as commit 635c4b9.
Your commit was automatically rebased without conflicts. |
|
@azuev-java Pushed as commit 635c4b9. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
|
/backport jdk26u |
|
@azuev-java the backport was successfully created on the branch backport-azuev-java-635c4b96-master in my personal fork of openjdk/jdk26u. To create a pull request with this backport targeting openjdk/jdk26u:master, just click the following link: The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk26u: |
Make caret color closer to the background color so it does appear as disabled caret.
Here is the comparison of default caret and the caret after the fix is applied:



Default white background:
After fix white background:
Default red background:
After fix with red background:
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30758/head:pull/30758$ git checkout pull/30758Update a local copy of the PR:
$ git checkout pull/30758$ git pull https://git.openjdk.org/jdk.git pull/30758/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 30758View PR using the GUI difftool:
$ git pr show -t 30758Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30758.diff
Using Webrev
Link to Webrev Comment