Source of ButtonImageDemo.java


  1: import javafx.application.Application;
  2: import javafx.scene.Scene;
  3: import javafx.stage.Stage;
  4: import javafx.scene.text.Font;
  5: import javafx.scene.layout.VBox;
  6: import javafx.scene.control.Button;
  7: import javafx.scene.image.Image;
  8: import javafx.scene.image.ImageView;
  9: 
 10: /**
 11: Simple demonstration of adding buttons to a JavaFX application.
 12: This version displays an icon for the Sunny Button.
 13: Nothing happens when the buttons are clicked.
 14: */
 15: public class ButtonImageDemo extends Application
 16: {
 17:    public static void main(String[] args)
 18:    {
 19:       launch(args);
 20:    }
 21: 
 22:    @Override
 23:    public void start(Stage primaryStage) throws Exception
 24:    {
 25:           VBox root = new VBox();
 26:       Button btnSunny;
 27:       Button btnCloudy;
 28:           btnSunny = new Button("Sunny");
 29:           btnCloudy = new Button("Cloudy");
 30: 
 31:             Image imgSmiley = new Image("smiley.gif");
 32:           btnSunny.setGraphic(new ImageView(imgSmiley));
 33: 
 34:           root.getChildren().add(btnSunny);
 35:           root.getChildren().add(btnCloudy);
 36: 
 37:              Scene scene = new Scene(root, 300, 100);
 38:       primaryStage.setTitle("Button Demo");
 39:       primaryStage.setScene(scene);
 40:       primaryStage.show();
 41:    }
 42: }