0

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

-1

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.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.