For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!
Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.
radioButton.setContentDisplay(ContentDisplay.LEFT);
package javafxsamples; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.ContentDisplay; import javafx.scene.control.RadioButton; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class RadioContentDisplayFailure extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) throws Exception { VBox radios = new VBox(15); for (ContentDisplay display: ContentDisplay.values()) { RadioButton radio = new RadioButton("radio-text: " + display); radio.setStyle("-fx-background-color: coral; -fx-border-color: red;"); radio.setContentDisplay(display); radios.getChildren().add(radio); } radios.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;"); stage.setScene(new Scene(radios)); stage.show(); } }
@Override public void start(Stage primaryStage) { RadioButton rb = new RadioButton("RadioButton"); StackPane root = new StackPane(); root.getChildren().add(rb); Scene scene = new Scene(root, 300, 200); primaryStage.setScene(scene); primaryStage.show(); Node radio = rb.lookup(".radio"); Node text = rb.lookup(".text"); double rx = radio.getBoundsInParent().getMinX(); double tx = text.getBoundsInParent().getMaxX(); radio.setLayoutX(tx); text.setLayoutX(rx); }
import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.text.Text; import javafx.stage.Stage; public class RadioBtns extends Application { @Override public void start(Stage primaryStage) { ToggleGroup grp = new ToggleGroup(); VBox vb = new VBox(5); vb.setPrefWidth(50); RadioButton rbHome = new RadioButton(); rbHome.setToggleGroup(grp); rbHome.setSelected(true); Label lHome = new Label("Home "); HBox hbHome = new HBox(); hbHome.setAlignment(Pos.CENTER_RIGHT); hbHome.getChildren().addAll(lHome, rbHome); RadioButton rbCal = new RadioButton(); rbCal.setToggleGroup(grp); Label lCal = new Label("Calendar "); HBox hbCal = new HBox(); hbCal.setAlignment(Pos.CENTER_RIGHT); hbCal.getChildren().addAll(lCal, rbCal); RadioButton rbContact = new RadioButton(); rbContact.setToggleGroup(grp); Label lContact = new Label("Contact "); HBox hbContact = new HBox(); hbContact.setAlignment(Pos.CENTER_RIGHT); hbContact.getChildren().addAll(lContact, rbContact); vb.getChildren().addAll(hbHome, hbCal, hbContact); Scene scene = new Scene(vb, 300, 250); primaryStage.setTitle("Radio buttons"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } }