Good morning, I'm learning about GUIs in JAVAfx, after giving a good search in google and within this site, I still can not make my button where I need this, I'm using the button. setLayoutX (); and the respective one for Y, however the button keeps appearing in the center of the screen ... here's my code.
package mainbar;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.image.*;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Mainbar extends Application {
@Override
public void start(Stage primaryStage) {
Image funcicon = new Image(getClass().getResourceAsStream("empleados.png"));
Button funcbtn = new Button();
funcbtn.setGraphic(new ImageView(funcicon));
funcbtn.setText("");
funcbtn.setPrefSize(65, 65);
funcbtn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
funcbtn.setLayoutX(250);
funcbtn.setLayoutY(250);
root.getChildren().add(funcbtn);
Scene scene = new Scene(root, 600, 450);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}