1  import javafx.application.Application;
  2  import javafx.geometry.Orientation;
  3  import javafx.scene.Scene;
  4  import javafx.scene.control.RadioButton;
  5  import javafx.scene.control.ScrollPane;
  6  import javafx.scene.control.SplitPane;
  7  import javafx.scene.control.TextArea;
  8  import javafx.scene.control.ToggleGroup;
  9  import javafx.scene.image.Image;
 10  import javafx.scene.image.ImageView;
 11  import javafx.scene.layout.StackPane;
 12  import javafx.scene.layout.VBox;
 13  import javafx.stage.Stage;
 14  
 15  public class SplitPaneDemo extends Application {
 16    private Image usImage = new Image(
 17      "https://liveexample.pearsoncmg.com/common/image/us.gif");
 18    private Image ukImage = new Image(
 19      "https://liveexample.pearsoncmg.com/common/image/uk.gif");
 20    private Image caImage = new Image(
 21      "https://liveexample.pearsoncmg.com/common/image/ca.gif");
 22    private String usDescription = "Description for US ...";
 23    private String ukDescription = "Description for UK ...";
 24    private String caDescription = "Description for CA ...";
 25  
 26    @Override // Override the start method in the Application class
 27    public void start(Stage primaryStage) {   
 28      VBox vBox = new VBox(10);
 29      RadioButton rbUS = new RadioButton("US"); 
 30      RadioButton rbUK = new RadioButton("UK"); 
 31      RadioButton rbCA = new RadioButton("CA");            
 32      vBox.getChildren().addAll(rbUS, rbUK, rbCA);
 33      
 34      SplitPane content = new SplitPane();
 35      content.setOrientation(Orientation.VERTICAL);
 36      ImageView imageView = new ImageView(usImage);
 37      StackPane imagePane = new StackPane();
 38      imagePane.getChildren().add(imageView);
 39      TextArea taDescription = new TextArea();   
 40      taDescription.setText(usDescription);
 41      content.getItems().addAll(
 42        imagePane, new ScrollPane(taDescription));
 43          
 44      SplitPane sp = new SplitPane();
 45      sp.getItems().addAll(vBox, content);
 46  
 47      Scene scene = new Scene(sp, 300, 250);           
 48      primaryStage.setTitle("SplitPaneDemo"); // Set the window title
 49      primaryStage.setScene(scene); // Place the scene in the window
 50      primaryStage.show(); // Display the window
 51      
 52      // Group radio buttons
 53      ToggleGroup group = new ToggleGroup();
 54      rbUS.setToggleGroup(group);
 55      rbUK.setToggleGroup(group);
 56      rbCA.setToggleGroup(group);
 57  
 58      rbUS.setSelected(true);
 59      rbUS.setOnAction(e -> {
 60        imageView.setImage(usImage);
 61        taDescription.setText(usDescription);
 62      });
 63      
 64      rbUK.setOnAction(e -> {
 65        imageView.setImage(ukImage);
 66        taDescription.setText(ukDescription);
 67      });
 68          
 69      rbCA.setOnAction(e -> {
 70        imageView.setImage(caImage);
 71        taDescription.setText(caDescription);
 72      });
 73    }
 74  
 75    // Launch the program from command-line
 76    public static void main(String[] args) {
 77      launch(args);
 78    }
 79  }