JavaFX CheckBox control font
import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.CheckBox; import javafx.scene.layout.BorderPane; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; import javafx.stage.Stage; public class Main extends Application { @Override/* w w w. ja v a2s.com*/ public void start(Stage primaryStage) { Scene scene = new Scene(getPane(), 450, 170); primaryStage.setTitle("java2s.com"); primaryStage.setScene(scene); primaryStage.show(); } protected BorderPane getPane() { BorderPane pane = new BorderPane(); Font fontBoldItalic = Font.font("Times New Roman", FontWeight.BOLD, FontPosture.ITALIC, 20); Font fontBold = Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 20); Font fontItalic = Font.font("Times New Roman", FontWeight.NORMAL, FontPosture.ITALIC, 20); Font fontNormal = Font.font("Times New Roman", FontWeight.NORMAL, FontPosture.REGULAR, 20); VBox paneForCheckBoxes = new VBox(20); paneForCheckBoxes.setPadding(new Insets(5, 5, 5, 5)); paneForCheckBoxes.setStyle("-fx-border-color: green"); CheckBox chkBold = new CheckBox("Bold"); CheckBox chkItalic = new CheckBox("Italic"); paneForCheckBoxes.getChildren().addAll(chkBold, chkItalic); pane.setRight(paneForCheckBoxes); chkBold.setFont(fontNormal); EventHandler<ActionEvent> handler = e -> { if (chkBold.isSelected() && chkItalic.isSelected()) { chkBold.setFont(fontBoldItalic); // Both check boxes checked } else if (chkBold.isSelected()) { chkBold.setFont(fontBold); // The Bold check box checked } else if (chkItalic.isSelected()) { chkBold.setFont(fontItalic); // The Italic check box checked } else { chkBold.setFont(fontNormal); // Both check boxes unchecked } }; chkBold.setOnAction(handler); chkItalic.setOnAction(handler); return pane; // Return a new pane } public static void main(String[] args) { launch(args); } }