现场演示
->
import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.CheckBox; import javafx.scene.control.Label; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; import javafx.stage.Stage; public class CheckBoxExample extends Application { public void start(Stage stage) { //创建复选框 CheckBox checkBox1 = new CheckBox("English"); CheckBox checkBox2 = new CheckBox("Hindi"); CheckBox checkBox3 = new CheckBox("Telugu"); CheckBox checkBox4 = new CheckBox("Tamil"); Label label = new Label("选择已知的语言:"); Font font = Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 12); label.setFont(font); //设置布局 VBox vBox = new VBox(5); vBox.setPadding(new Insets(5, 5, 5, 50)); vBox.getChildren().addAll(label, checkBox1, checkBox2, checkBox3, checkBox4); //设置舞台 Scene scene = new Scene(vBox, 595, 150, Color.BEIGE); stage.setTitle("Check Box Example"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
输出结果