Closed Bios-Marcel closed 2 years ago
SwingX PromptSupport does some tricks that FlatLaf does not like.
It replaces text field UI delegate FlatTextFieldUI
with own class BuddyTextFieldUI
.
Also border FlatTextBorder
is replaced with BuddyLayoutAndBorder
.
Layout manager is replaced.
Seems to be very complicated and tricky...
This avoids that FlatLaf paint text field background. Also if you enter text and use Flat IntelliJ or Darcula themes (with outside focus borders), the background is not correct:
Not sure whether this is fixable...
If you use FlatLaf only, I would recommend using placeholder texts instead:
a.putClientProperty( "JTextField.placeholderText", "Prompt" );
With next version 0.46, you can use FlatTextField
from "extras" subproject:
FlatTextField a = new FlatTextField();
a.setPlaceholderText( "Prompt" );
Ah thanks for the info. Yeah, i don't know, but maybe we can fix it in swingx. We are actually using our own fork of swingx, so maybe there's something we can do.
We have the same problem. We are also using the foreground color option to hint error messages in red (e.g. missing entries). We are using PromptSupport directly in our derived JTextField class, so we could use the ClientProperty if FlatLaf is set instead of using PromptSupport but we are missing the color option.
JXSearchField has the same problem when setting the prompt.
Had another look at the issue.
The problem is that FlatTextFieldUI
background painting is not invoked.
PromptSupport
replaces text field UI delegate FlatTextFieldUI
with own class BuddyTextFieldUI
,
which delegates painting to FlatTextFieldUI
, but only if text field is not empty.
If empty, then it fills background itself if text field is opaque.
But in FlatLaf it is not opaque.
Here is the related code (in PromptTextUI):
public void update(Graphics g, JComponent c) {
if (shouldPaintPrompt((JTextComponent) c)) {
super.update(g, c);
} else {
delegate.update(g, c);
}
}
One solution would be to make text fields opaque if they use PromptSupport
.
This works fine for themes "Flat Light" and "Flat Dark", but has issues with "IntelliJ/Darcual" themes (see my previous post).
Another solution would be to modify SwingX PromptTextUI
.
I think following should work:
public void update(Graphics g, JComponent c) {
if (shouldPaintPrompt((JTextComponent) c)) {
if (!c.isOpaque()) {
delegate.update(g, c);
}
super.update(g, c);
} else {
delegate.update(g, c);
}
}
Unfortunately, there is nothing I can do to fix this issue in FlatLaf...
Thanks for looking into it again, I'll be closing the issue then.
As soon as you type any text, the color is correct.
Dependencies: