-
Notifications
You must be signed in to change notification settings - Fork 235
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
Default JLabel tooltip should be white for HTML text #420
Comments
This issue indeed exists and it didn't appear in previous versions because of the specifics of Pretty much what happens is when component detects HTML content within its own text it generates a special Previously (in v1.28 and earlier) it worked just fine because WebLaF was still using I am still not sure how I will fix this problem and I am trying some different approaches right now. Either way I will have to fix it as it also affects all other components in the same manner, it is just harder to notice because default |
- BasicHTML.java - Replacement for Swing `javax.swing.plaf.basic.BasicHTML` added to decrease amount of redundant component repaints and allow customizing basic HTML foreground color [ #420 ] - AbstractTextContent.java - Now contains basic HTML `View` retrieval and check based on newly added `BasicHTML` class - Removed redundant `javax.swing.plaf.basic.BasicHTML` utility class usage from all text content implementations - AbstractTextContent.java, AbstractStyledTextContent.java - Fixed text Y coordinate calculation algorithms, all centered texts should be positioned correctly - AbstractStyledTextContent.java - Fixed possibility of additional trimmed parts appearance in text containing different styles - AbstractTextContent.java - Moved paint color setup to the main painting method - AbstractTextContent.java - Added proper checks for horizontal and vertical alignments - AbstractContent.java - Restored proper content clipping ToolTip - WebToolTipUI.java - Removed redundant HTML content updates, removed basic UI usage, added proper basic settings initialization - WToolTipUI.java, WebToolTip.java - New appropriate intermediate UI for `WebToolTip` component - tooltip.xml - Enhanced dark skin tooltip colors to emphasize it amongst other UI elements StyledLabel - StyleRanges.java - Fixed NPE for the `null` text within any component using styled text content Skins - button.xml, togglebutton.xml, splitbutton.xml, checkbox.xml, radiobutton.xml, tristatecheckbox.xml - Removed redundant copy-pasted icon definition Utilities - SwingUtils.java - Updated `isUIResource` method to accept any objects as there are multiple `UIResource` types available
Also, generally speaking, HTML should always be your last resort as its rendering is extremely slow in Swing. For example compared to plain text - HTML could be up to 100 times slower and that is not an exaggeration. The solution I would propose (in case you are using latest First of all, WebLaF in its current iteration has each unique component broken down into small pieces - either parts of decoration or contents. You can clearly see that in the style XML for any component, for example button ( taken from this file ): <style type="button" padding="2,4,2,4">
<painter>
<decorations>
<decoration>
<WebShape round="3" />
<WebShadow type="outer" width="2" />
<LineBorder color="170,170,170" />
<GradientBackground>
<color>white</color>
<color>223,223,223</color>
</GradientBackground>
<ButtonLayout>
<ButtonIcon constraints="icon" />
<ButtonText constraints="text" color="black" />
</ButtonLayout>
</decoration>
<decoration states="focused">
<LineBorder color="85,130,190" />
</decoration>
<decoration states="pressed">
<WebShadow type="outer" opacity="0" />
<WebShadow type="inner" width="6" />
<ColorBackground color="210,210,210" />
</decoration>
<decoration states="disabled">
<WebShadow type="outer" opacity="0" />
<LineBorder color="lightGray" />
<ButtonLayout>
<ButtonText color="120,120,120" />
</ButtonLayout>
</decoration>
</decorations>
</painter>
</style> You can see how component is broken down into small parts for each of its state. It has everything - shape, shadow, border, background, contents and layout - specified explicitly with their own settings. You can of course control all those settings if you want to, it was described in this wiki article in details. In the button skin file you can also find the next separate style: <!-- Button supporting styled text -->
<style type="button" id="styled">
<painter>
<decorations>
<decoration>
<ButtonLayout>
<ButtonIcon constraints="icon" />
<StyledButtonText constraints="text" color="black" />
</ButtonLayout>
</decoration>
<decoration states="disabled">
<ButtonLayout>
<StyledButtonText color="120,120,120" ignoreStyleColors="true" />
</ButtonLayout>
</decoration>
</decorations>
</painter>
</style> This is exactly the styled version of the component I was talking about. As you might see from the XML - the only different thing it uses is So here is a small example: public class StyledButton
{
public static void main ( final String[] args )
{
WebLookAndFeel.install ();
final String text = "{Sample:b} {styled:c(red)} button";
final WebButton styled = new WebButton ( StyleId.buttonStyled, text );
final WebButton plain = new WebButton ( text );
TestFrame.show ( 15, false, 15, styled, plain );
}
} And the result: So the style attached to the button actually changes its text rendering behavior. The same trick can be applied to the tooltips and the only problem is that you cannot explicitly set tooltip style ID and you probably don't even want to. So what you need to do is override the default tooltip style which looks like this: <style type="tooltip">
<painter>
<decorations>
<decoration>
<WebShape round="2" />
<LineBorder color="black" />
<ColorBackground color="black" />
<ToolTipText padding="2,4,2,4" color="245,245,245" />
</decoration>
</decorations>
</painter>
</style> With the styled version of content: <style type="tooltip">
<painter>
<decorations>
<decoration>
<StyledToolTipText padding="2,4,2,4" color="245,245,245" />
</decoration>
</decorations>
</painter>
</style> Now all of the default tooltips will support style syntax of This is the styled text for the second example: final String text = "{Sample:b} {styled:c(red)} button" + "\n" + "With some {hard:u} line breaks" + "\n\n" + "That easily!"; And this is the same text using HTML: final String text = "<html><b>Sample</b> <font color='red'>styled</font> button<br>With some <u>hard</u> line breaks<br><br>That easily!</html>"; To summ up - you will need to do next steps to enable styling syntax in tooltips:
That might sound as a lot to do, but it is actually not. Plus you will be able to customize or create any additional styles for any components if you want to as you would already have a custom skin. It is important to mention that all of the examples above are only applicable to WebLaF v1.2.9 You can find the latest |
Also, I have pushed a fix ( 462b375 ) for HTML within the tooltips, labels, buttons and other components - it should now properly use text color specified in the skin. That took quite a bit of effort and I had to make my own copy of I will be doing some more related changes soon, but everything should be working fine with the latest build which you can here: https://oss.sonatype.org/content/repositories/snapshots/com/weblookandfeel/ |
Thanks for your explanation and your quick reply/fix. It sounds great and I will definitely give it a try. |
Regarding the link https://oss.sonatype.org/content/repositories/snapshots/com/weblookandfeel/ that you referred to. |
@fjoncourt If you will have any questions - feel free to ask in chat or just mail me directly. @Endogen I haven't fixed the manifest file for the maven builds of modules, so those pretty much have some default manifests without any information about the main class. If you want to run demo - you can download the fully packed version from the site: http://weblookandfeel.com/downloads/styling/ - specifically - weblaf-demo-1.29.jar - it is an artifact built from Be aware that builds on the site might sometimes be slightly behind the maven ones as I have to update those manually and I do not update them on every single commit to the You can find the short guide on how to build stuff in this article on wiki. |
Hi,
With release 1.28
looks like that:
With release 1.29 the text is hidden:
But using
it displays:
Could you set the default font color for embedded html to white so that we can see the text :)
Regards,
The text was updated successfully, but these errors were encountered: