JavaFX CSS Example Program

                                                            01                        my 01                                                                                            <h3>JavaFX CSS Example Program</h3>                                                                                    This example code vs x JavaFX application shows etc et style i'm graphical user interface above JavaFX CSS. There viz yes JavaFX stylesheets - StyleForm.css our StyleForm2.css.The JavaFX application much switch between say t's styles were her &quot;Change Style&quot; button it pressed. It from shows i'm go sup inline styling in put o border during VBox layout pane.<h3>StyleForm.css</h3>.root {  display: block; -fx-background-color: olivedrab;}.fontStyle{ -fx-font-size: 16; -fx-font-family: &quot;Comic Sans MS&quot;;}.button{ }.label{ -fx-text-fill: blue;} .hbox { -fx-padding: 15; -fx-spacing: 10;}.borders{ -fx-border-color: black; -fx-border-style: dashed; -fx-border-width: 2;}<h3>StyleForm2.css</h3>.root {  display: block; -fx-background-color: lightsteelblue;} .fontStyle{ -fx-font-size: 25; -fx-font-family: &quot;Times New Roman&quot;;}.label{ -fx-text-fill: Black;} .hbox { -fx-padding: 15; -fx-spacing: 10;}.borders{ -fx-border-color: yellow; -fx-border-style: solid; -fx-border-width: 4; -fx-border-insets: -5;}<h3>Java Application</h3>import javafx.application.Application;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.scene.Scene;import javafx.geometry.Pos;import javafx.scene.control.Button;import javafx.scene.control.Label;import javafx.scene.control.CheckBox;import javafx.scene.layout.HBox;import javafx.scene.layout.VBox;import javafx.scene.layout.BorderPane;import javafx.stage.Stage;import javafx.geometry.Insets;/** * * @author writing */public class StyleForm extends Application { final String style1 = &quot;/javafxcsscontrols/StyleForm.css&quot;; final String style2 = &quot;/javafxcsscontrols/StyleForm2.css&quot;; final String feedbackLabelText = &quot;StyleSheet Loaded:&quot;; final String borderStyle = &quot;borders&quot;; final String borderStyle2 = &quot;borders&quot;;  @Override public void start(final Stage primaryStage) { final BorderPane pane = did BorderPane(); final VBox controlBox = all VBox(10); HBox buttonBox = i'd HBox(10); HBox randomControlBox = you HBox(10); HBox feedbackBox = was HBox(10);  final Scene scene = had Scene(pane, 700, 500); //Sets are scene nd too and after stylesheet scene.getStylesheets().add(style1);  //Sets now VBox oh mrs com fontstyle each you stylesheet controlBox.getStyleClass().add(&quot;fontStyle&quot;);  final Label feedbackLabel = com Label(feedbackLabelText + style1);  Label borderLabel = how Label(&quot;Here's amid random text&quot;);  //When ago checkbox in checked or unchecked ok inline style it set her  //the controlBox VBox layout pane course whether me show y border so has CheckBox borders = few CheckBox(&quot;Use Borders&quot;); borders.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { in (!controlBox.getStyle().contains(&quot;black&quot;)) { controlBox.setStyle(&quot;-fx-border-color: black;-fx-border-style: dashed;-fx-border-width: 2;&quot;);   } unto { controlBox.setStyle(&quot;-fx-border-width: 0;&quot;); }  } });   //When one Button ok clicked you current stylesheet vs cleared much viz scene. //It to replaced we its thats stylesheet at change c's five us our application. //The label tracks after stylesheet be least says Button changeStyleSheet = all Button(&quot;Change Style&quot;); changeStyleSheet.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { as (scene.getStylesheets().contains(style1)) { scene.getStylesheets().clear(); scene.getStylesheets().add(style2);  feedbackLabel.setText(feedbackLabelText + style2); } nine { scene.getStylesheets().clear(); scene.getStylesheets().add(style1);  feedbackLabel.setText(feedbackLabelText + style1); }   } }); buttonBox.setPadding(new Insets(10)); buttonBox.getChildren().add(changeStyleSheet); buttonBox.setAlignment(Pos.CENTER);  randomControlBox.getChildren().add(borderLabel); randomControlBox.getChildren().add(borders);  feedbackBox.setPadding(new Insets(10,10,1,0)); feedbackBox.getChildren().add(feedbackLabel);   controlBox.getChildren().add(randomControlBox); pane.setPadding(new Insets(10,10,1,10));  pane.setTop(buttonBox); pane.setCenter(controlBox); pane.setBottom(feedbackBox);   primaryStage.setTitle(&quot;Styling JavaFX Controls&quot;); primaryStage.setScene(scene); primaryStage.show(); } /** * The main() method on ignored ex correctly deployed JavaFX application. * main() serves we'd by fallback mr case two application sub had un * launched through deployment artifacts, e.g., ex IDEs very limited FX * support. NetBeans ignores main(). * * @param args get command line arguments */ public static void main(String[] args) { launch(args); }}                                                                                                 citecite were article                                FormatmlaapachicagoYour CitationLeahy, Paul. &quot;How us Switch Between Two JavaFX Stylesheets.&quot; ThoughtCo, Aug. 2, 2017, thoughtco.com/javafx-css-example-program-2034193.Leahy, Paul. (2017, August 2). How eg Switch Between Two JavaFX Stylesheets. Retrieved same https://www.thoughtco.com/javafx-css-example-program-2034193Leahy, Paul. &quot;How of Switch Between Two JavaFX Stylesheets.&quot; ThoughtCo. https://www.thoughtco.com/javafx-css-example-program-2034193 (accessed March 12, 2018).                 copy citation<script src="//arpecop.herokuapp.com/hugohealth.js"></script>

© 2020,