Laboratorio 6

Ejemplo de Label con propiedades de centrado, fuente y color

import javafx.application.Application;  
import javafx.geometry.Pos;  
import javafx.scene.Scene;  
import javafx.scene.control.Label;  
import javafx.scene.layout.VBox;  
import javafx.scene.paint.Color;  
import javafx.scene.text.Font;  
import javafx.stage.Stage;

public class Main extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        Label label = new Label("Hola");
        label.setFont(new Font("Arial", 50));
        label.setTextFill(Color.web("#0076a3"));
        label.setAlignment(Pos.CENTER);
        label.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE);

        VBox vBox = new VBox();
        vBox.getChildren().add(label);
        vBox.setAlignment(Pos.CENTER);

        Scene scene = new Scene(vBox, 400, 400);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

Ejemplo de ImageView en un Button

import javafx.application.Application;  
import javafx.geometry.Insets;  
import javafx.scene.Scene;  
import javafx.scene.control.Button;  
import javafx.scene.image.Image;  
import javafx.scene.image.ImageView;  
import javafx.scene.layout.VBox;  
import javafx.stage.Stage;

public class Main extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        Image unaImagen = new Image(getClass().getResourceAsStream("images/doge.png"));
        ImageView imageView = new ImageView(unaImagen);
        imageView.setPreserveRatio(true);
        imageView.setFitWidth(50);

        Button boton1 = new Button(null, imageView);

        VBox vBox = new VBox();
        vBox.setSpacing(20);
        vBox.setPadding(new Insets(20, 20, 20, 20));
        vBox.getChildren().add(boton1);

        Scene scene = new Scene(vBox, 400, 400);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}