Algunos componentes de JavaFX

Por 9.99€ al mes tendrás acceso completo a todos los cursos. Sin matrícula ni permanencia.

Botón

Button btn = new Button("Calcular");

Cuadro de texto

TextField n2 = new TextField ();

ComboBox

ComboBox op = new ComboBox(options);

Para alimentar la ComboBox:

Con código Java:

ObservableList<String> options = FXCollections.observableArrayList("+","-","*");
final ComboBox op = new ComboBox(options);

Desde el fxml:

<?import javafx.collections.FXCollections ?>
<ComboBox fx:id="op" prefWidth="150.0">
	<items>
		<FXCollections fx:factory="observableArrayList">
			<String fx:value="+" />
			<String fx:value="-" />
			<String fx:value="*" />
			<String fx:value="/" />
		</FXCollections>
	</items>
	<value>
		<String fx:value="+" />
	</value>
</ComboBox>

Texto

Text txt = new Text("Ha ganado el jugador " + color);

Mensaje de alerta

Stage stage = (Stage)((Button)e.getSource()).getScene().getWindow();

final Stage dialog = new Stage();
dialog.initModality(Modality.APPLICATION_MODAL);
dialog.initOwner(stage);
VBox dialogVbox = new VBox();
            
Text txt = new Text("Ha ganado el jugador " + color);
dialogVbox.setAlignment(Pos.CENTER);
VBox.setVgrow(txt, Priority.ALWAYS);
dialogVbox.getChildren().add(txt);
Scene dialogScene = new Scene(dialogVbox, 300, 200);
dialog.setScene(dialogScene);
dialog.show();  

Por 9.99€ al mes tendrás acceso completo a todos los cursos. Sin matrícula ni permanencia.