CheckBox_Visiblity1
 
 
Code :

package javafxtemplate1;

import java.sql.SQLException;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.CheckBox;
import javafx.scene.effect.DropShadow;

import javafx.stage.Stage;

public class JavaFXTemplate1 extends Application {
CheckBox chkb1 = new CheckBox("SingleTon");
CheckBox chkb2 = new CheckBox("DoubleTon");
Label label1 = new Label("Label");
@Override
public void start(Stage primaryStage) {
Group groot = new Group();
//CheckBox chkb1 = new CheckBox("SingleTon");
chkb1.setLayoutX(110);chkb1.setLayoutY(20);
//CheckBox chkb2 = new CheckBox("DoubleTon");
chkb2.setLayoutX(190);chkb2.setLayoutY(20);
chkb2.setVisible(false);
//Label label1 = new Label("Label");
label1.setLayoutX(90);label1.setLayoutY(40);
Button btn2 = new Button("Exit Platform");
btn2.setLayoutX(100);btn2.setLayoutY(80);
//Class Implementing Event handler
btn2.setOnAction(new DemoEventHandler1(){ });
//
//chkb1.getSelectionModel().select(index)
chkb1.selectedProperty().addListener(this::changed);

//
groot.getChildren().addAll(btn2,label1, chkb1, chkb2);
Scene scene = new Scene(groot, 350, 150);
primaryStage.setScene(scene);
primaryStage.setTitle("JavaFx CheckBox");
primaryStage.show();
}

public static void main(String[] args) throws SQLException {
launch(args);
}
public void changed(ObservableValue<? extends Boolean> observable,
Boolean oldValue,Boolean newValue) {
String msg;
DropShadow shadow = new DropShadow();
if (chkb1.isSelected()) {
msg = "Yes";
chkb1.setEffect(shadow);
chkb2.setVisible(true);
} else {
msg = "No";
chkb1.setEffect(null);
chkb2.setVisible(false);
}
this.label1.setText("Box Checked? " + msg);
}
}
class DemoEventHandler1 implements EventHandler<ActionEvent>{

@Override
public void handle(ActionEvent event) {
Platform.exit();

}
}

Runtime Views