document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import javafx.application.Application;
  2. import javafx.geometry.Insets;
  3. import javafx.scene.Scene;
  4. import javafx.scene.control.Button;
  5. import javafx.scene.image.Image;
  6. import javafx.scene.image.ImageView;
  7. import javafx.scene.layout.BorderPane;
  8. import javafx.scene.layout.HBox;
  9. import javafx.scene.layout.VBox;
  10. import javafx.stage.Stage;
  11.  
  12. /**
  13.  *
  14.  * @author zoranpavlovic.blogspot.com
  15.  */
  16. public class imageToButton extends Application {
  17.     /**
  18.      * @param args
  19.      *            the command line arguments
  20.      */
  21.     public static void main(String[] args) {
  22.         Application.launch(args);
  23.     }
  24.  
  25.     @Override
  26.     public void start(Stage primaryStage) {
  27.         primaryStage.setTitle("Image to Button");
  28.  
  29.         // BorderPane
  30.         BorderPane bp = new BorderPane();
  31.  
  32.         // HBox
  33.         HBox hb = new HBox();
  34.         hb.setPadding(new Insets(15, 15, 15, 12));
  35.         hb.setSpacing(10);
  36.  
  37.         // HBox
  38.         VBox vb = new VBox();
  39.         vb.setPadding(new Insets(15, 12, 15, 12));
  40.         vb.setSpacing(10);
  41.  
  42.         // Adding images
  43.         Image img1 = new Image(getClass().getResourceAsStream("about.png"));
  44.         Image img2 = new Image(getClass().getResourceAsStream("close.png"));
  45.  
  46.         // Adding buttons and images to buttons with no text on buttons
  47.         Button button1 = new Button("", new ImageView(img1));
  48.         hb.getChildren().add(button1);
  49.         Button button2 = new Button("", new ImageView(img2));
  50.         hb.getChildren().add(button2);
  51.         // Adding buttons and images with text on buttons
  52.         Button button3 = new Button("Info Button", new ImageView(img1));
  53.         vb.getChildren().add(button3);
  54.  
  55.         bp.setTop(hb);
  56.         bp.setCenter(vb);
  57.  
  58.         // Adding GridPane to the scene
  59.         Scene scene = new Scene(bp);
  60.         primaryStage.setScene(scene);
  61.         primaryStage.show();
  62.     }
  63. }
');