简体   繁体   中英

Java Swing import CSS Style

How can I import my CSS style into a Java Application?

I have a normal CSS with the JButton#btn class styles and so on.

But how can I import it into my Application?

I want to turn the GUI with Java Swing with the file like in Python with the QT Framework

Swing doesn't work that way. To change the look of a Swing GUI, we set a Pluggable Look and Feel . It is true hat certain Swing components (including JButton ) will render parts of HTML 3.2 and simple styles, and can indeed import stylesheets (and understand very basic CSS), it is implemented in a 'less than ideal' way. For example, if a button styled with HTML/CSS is disabled, it does not gain the default 'disabled look' for a button.

I am led to understand the Java-FX GUI toolkit allows more the style you are after. See the JavaFX CSS Reference Guide for details.

You don't import CSS into an application as a whole, CSS is applied directly to webpages. In order to insert an external CSS style into a page, you need to add this into <head> part

<link rel="stylesheet" type="text/css" href="mystyle.css"> 

You can check w3schools for more info about inserting CSS into a page.

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