tags:

views:

392

answers:

5
+1  Q: 

css with swing

how to introduce CSS style for various swing components like JButton,Jpanel etc. in a swing application?

+2  A: 

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.

Michael Borgwardt
This is inaccurate. In my experience, using a <style> element in a <head> element after your <html> opening, you can put CSS rules. Note, however, that Swing support is CSS 1.0 at most - it looks like background will work, but overflow won't (which is quite a shame in my case...).
splintor
+2  A: 

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
A: 

I bookmarked this long back, but never evaluated:

project home page
article

Santhosh Kumar T
+1  A: 

Maybe you could use this "javacss" project:

https://javacss.dev.java.net/

Frank Hardisty
I've been using its predecessor from the now defunct JAXX. Using css is a great way to separate out presentation details from your Java code, and the implementation is pretty good.
Geoffrey Zheng
+1  A: 

Like this --> http://today.java.net/article/2003/10/05/swing-and-css

Achi Furtan