0

I made a CSS

.button{ 
    -fx-pref-height: 28px;
    -fx-pref-width: 100px;
}

and I want to add this particular CSS to all the scenes in my application. How am I suppose to so? Glad for any help.

To be accurate, I have a radio button in one scene and by clicking it I want all the buttons in different scenes present in my application changes according to this CSS.

Worthwelle
  • 1,244
  • 1
  • 16
  • 19
Ziva
  • 21
  • 5
  • Please provide context on what kind of application you are building so that we can assist you better. For example, are you using JavaScript to add CSS classes to elements? How many HTML files do you want to add the CSS to? etc. – Andrew Fan Jun 04 '18 at 18:03
  • 1
    @AndrewFan The post is tagged JavaFX, so this is a JavaFX application. There is no HTML. I'll edit the CSS tag for the benefit of all the CSS crowd who don't know that you can use CSS outside of a web application... ;) – James_D Jun 04 '18 at 18:13
  • @James_D Thank you for the corrections. I have explained my query more accurately in the comment below. Suggest me a way to achieve it. – Ziva Jun 04 '18 at 18:24
  • 1
    @Ziva You should make clarifications in the question itself. (Ideally, you should provide enough information at the beginning so that people don't spend their time providing answers that aren't what you want. Create a [MCVE].) – James_D Jun 04 '18 at 18:26
  • @James_D I am new to this portal, therefore, its the situation. I've edited the question. – Ziva Jun 04 '18 at 18:30
  • Just add the stylesheet to every scene, using the code in the answer that's already posted? There are probably better solutions involving CSS pseudoclasses, but the question is nowhere near specific enough to know if this is the case. (I guess you didn't read the link in my previous comment.) – James_D Jun 04 '18 at 18:31
  • @James_D Thank you for the clarification - I've never seen CSS being used outside of web apps so I assumed it was a web app. – Andrew Fan Jun 04 '18 at 19:46

1 Answers1

0

Put this CSS into an external stylesheet and include it in each scene.

Scene scene = new Scene(new Group(), 500, 400);
scene.getStylesheets().add("path/stylesheet.css");

See the documentation here.

Worthwelle
  • 1,244
  • 1
  • 16
  • 19
  • I have gone through this documentation earlier but found nothing relevant to work. To be accurate, I have a radio button in one scene and by clicking it I want all the buttons in different scenes present in my application changes according to this css. I am not getting how to make changes in all scenes through this css? – Ziva Jun 04 '18 at 18:22
  • apart from your custom stylesheet (which you can set on the application level via userStyleSheet) you need a) a custom state of your buttons, b) logic to toggle the state of all buttons - pseudoClass comes handy for such state, if you need just on/off – kleopatra Mar 07 '19 at 10:37