By using
'setSelected' method of CheckBox class, you can select the check box by
default.
Ex
CheckBox
checkBox1 = new CheckBox();
checkBox1.setText("Chess");
checkBox1.setSelected(true);
Find the below working application.
package com.sample.demos; import java.io.FileNotFoundException; import java.net.MalformedURLException; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.CheckBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class CheckBoxApp extends Application { @Override public void start(Stage primaryStage) throws FileNotFoundException, MalformedURLException { CheckBox checkBox1 = new CheckBox(); checkBox1.setText("Chess"); checkBox1.setSelected(true); CheckBox checkBox2 = new CheckBox("Cricket"); VBox vbox = new VBox(10, checkBox1, checkBox2); Scene scene = new Scene(vbox, 400, 300); /* Set the scene to primaryStage, and call the show method */ primaryStage.setTitle("JavaFX CheckBox Example"); primaryStage.setScene(scene); primaryStage.show(); } }
TestFX.java
package com.sample.demos; import javafx.application.Application; public class TestFX { public static void main(String args[]) { Application.launch(CheckBoxApp.class, args); } }
No comments:
Post a Comment