0

Sorry, I have just begun learning javaFX and cannot figure out how to get all of my icons on buttons the same size. I tried a couple things but could not get it working, all help is appreciated. Thank you!

Wont let me post my question unless I add more details but I cant think of anything else to put so just ignore this whole paragraph as I ramble on so I can post my question and continue coding my game.

    public class Main extends Application {
    Stage window;
    Button button;
    Scene scene1, scene2;

    public static final int ROCK = 0;
    public static final int PAPER = 1;
    public static final int SCISSORS = 2;
    public static int userChoice;


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

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

      //Layout 1
      VBox layout = new VBox(20);
      Label label = new Label("Rock Paper Scissors");
      Button myButton = new Button("Start"); 
      myButton.setOnAction(e -> window.setScene(scene2));
      Button exit = new Button("Exit");
      exit.setOnAction(e -> System.exit(0));
      layout.getChildren().addAll(label, myButton, exit);
      layout.setAlignment(Pos.CENTER);
      scene1 = new Scene(layout, 300, 300);

      //Layout 2
      BorderPane border = new BorderPane();
      VBox layout1 = new VBox(10);
      Label label1 = new Label("Choose One");
      layout1.setAlignment(Pos.CENTER);


      //Layout 3
      HBox layout2 = new HBox(10);


      //Rock Image Button
      Image rockIm = new Image(getClass().getResourceAsStream("Rock2.png"));
      Button rock = new Button();
      rock.setGraphic(new ImageView(rockIm));
      rock.setOnAction(e -> userChoice = ROCK);


      //Paper Image Button
      Image paperIm = new 
      Image(getClass().getResourceAsStream("Paper2.png"));
      Button paper = new Button();
      paper.setGraphic(new ImageView(paperIm));
      paper.setOnAction(e -> userChoice = PAPER);


      //Scissor Image Button
      Image scissorIm = new 
      Image(getClass().getResourceAsStream("Scissor2.png"));
      Button scissors = new Button();
      scissors.setGraphic(new ImageView(scissorIm));
      scissors.setOnAction(e -> userChoice = SCISSORS);


      Button quit = new Button("Return");
      quit.setOnAction(e -> window.setScene(scene1));
      layout2.getChildren().addAll(rock, paper, scissors, quit);
      layout2.setAlignment(Pos.CENTER);
      scene2 = new Scene(layout2, 300, 300);

      window.setTitle("Rock Paper Scissors");
      window.setScene(scene1);
      window.show();
  }

}

  • 3
    Possible duplicate of [Making all button size same](https://stackoverflow.com/questions/11536089/making-all-button-size-same) – ChristophE Apr 09 '19 at 05:03
  • 6
    @ChristophE It is not a duplicate of your referenced question because it is for Swing and this one is for JavaFX. – mipa Apr 09 '19 at 07:09
  • @ChristophE You simply can't link a Swing answer for a JavaFX question... Not the same behaviour. For the OP, have a look on CSS for JavaFX. – Pagbo Apr 09 '19 at 07:10
  • 2
    Have a look at this Oracle document. It specifically talks about you issue. https://docs.oracle.com/javase/8/javafx/layout-tutorial/size_align.htm#JFXLY133 – mipa Apr 09 '19 at 07:14
  • Another good resource so you can avoid the "rambling" paragraphs to fill up space: "[ask] a Good Question" and "How to Create a [mcve]"... – Zephyr Apr 09 '19 at 18:51

0 Answers0