How to introduce CSS style for various Swing components like JButton
, JPanel
etc. in a Swing application?
Asked
Active
Viewed 1.1k times
9

Lukas Rotter
- 4,158
- 1
- 15
- 35
-
Here is an open source lbrary [that](http://code.google.com/p/java-universal-css-engine/) helps to style swing components using custom css rules. – Dec 09 '12 at 17:36
3 Answers
5
You don't. The HTML parser that some Swing components use does not even support most HTML tags; it does not support CSS at all.
If you need advanced HTML support in a Java app, you will have to use one of the third-party components that provide it.

Community
- 1
- 1

Michael Borgwardt
- 342,105
- 78
- 482
- 720
2
You can use the various Swing properties to describe UI defaults that will be shared by all components - like fonts etc - but as Michael mentions; there's no way to do full CSS
. For example:
FontUIResource f = new FontUIResource("Tahoma", Font.BOLD, 12)
UIManager.put("MenuBar.font", f); //javax.swing.UIManager
UIManager.put("Menu.font", f);
UIManager.put("RootPane.titleFont", f);

oxbow_lakes
- 133,303
- 56
- 317
- 449
1
I used javacss successfully in some projects. I dropped javafx support from it for my purpose and fixed a severe memory leak (there still maybe some more). I created a github project for that, since the license is gpl:

cyberbeat
- 45
- 1
- 6
-
Is this the same JavaCSS described in this article: [Styling Swing Components with Java CSS](http://www.quepublishing.com/articles/article.aspx?p=1390174)? – will Feb 12 '17 at 23:51
-
It IS the same, at least it seams so to me. The article references exactly the same packages and class names. This was the first blog introduction from the original author I think: https://community.oracle.com/blogs/enicholas/2008/07/17/introducing-java-css – cyberbeat Feb 14 '17 at 17:20