I am trying to give a specific position to a button in Javafx, but it is not working, where is my error?

0

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);
}

}
    
asked by Brlesskoin 06.07.2016 в 14:50
source

1 answer

1

Resolvi, I should replace the stackpane with pane normal, the code is like this;

Pane root = new Pane();
    funcbtn.setLayoutX(250);
    funcbtn.setLayoutY(250);
    root.getChildren().add(funcbtn);
    clibtn.setLayoutX(350);
    clibtn.setLayoutY(350);
    root.getChildren().add(clibtn);
    Scene scene = new Scene(root, 600, 450);
    
answered by 06.07.2016 в 15:37