简体   繁体   中英

CSS Styling with Swing

如何在Swing应用程序中为JButtonJPanel等各种Swing组件引入CSS样式?

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 .

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);

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:

https://github.com/cyberbeat/java-css

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM