Wednesday, 23 May 2018

JavaFX: RadioButton: Create Radio button

RadioButton class provides below constructors to create radio button widget.

public RadioButton()
public RadioButton(String text)

Ex
RadioButton button1 = new RadioButton();
button1.setText("Radio Button1");

RadioButton button2 = new RadioButton("Radio Button2");

Find the below working application.

RadioButtonApp.java
package com.sample.demos;

import static javafx.geometry.Pos.CENTER;

import java.io.FileNotFoundException;
import java.net.MalformedURLException;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class RadioButtonApp extends Application {

 @Override
 public void start(Stage primaryStage) throws FileNotFoundException, MalformedURLException {

  RadioButton button1 = new RadioButton();
  button1.setText("Radio Button1");

  RadioButton button2 = new RadioButton("Radio Button2");

  VBox vBox = new VBox(10, button1, button2);
  vBox.setAlignment(CENTER);

  Scene scene = new Scene(vBox, 400, 400);

  /* Set the scene to primaryStage, and call the show method */
  primaryStage.setTitle("JavaFX Radio Button 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(RadioButtonApp.class, args);
 }
}




Previous                                                 Next                                                 Home

No comments:

Post a Comment