daily pastebin goal
44%
SHARE
TWEET

LayoutTest

a guest Feb 13th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package sample;
  2.  
  3. import javafx.application.Application;
  4. import javafx.fxml.FXMLLoader;
  5. import javafx.geometry.Insets;
  6. import javafx.geometry.Pos;
  7. import javafx.scene.Group;
  8. import javafx.scene.Parent;
  9. import javafx.scene.Scene;
  10. import javafx.scene.canvas.Canvas;
  11. import javafx.scene.canvas.GraphicsContext;
  12. import javafx.scene.effect.BlendMode;
  13. import javafx.scene.layout.*;
  14. import javafx.scene.paint.Color;
  15. import javafx.scene.shape.Rectangle;
  16. import javafx.stage.Stage;
  17. import javafx.scene.shape.*;
  18. import javafx.scene.text.*;
  19.  
  20. public class Main extends Application {
  21.  
  22.     @Override
  23.     public void start(Stage primaryStage) throws Exception{
  24.  
  25.         Group root = new Group();
  26.         Scene scene = new Scene(root, 800, 600);
  27.  
  28.         primaryStage.setTitle("Test");
  29.  
  30.         root.getChildren().addAll(addVBox());
  31.  
  32.         primaryStage.setScene(scene);
  33.         primaryStage.show();
  34.  
  35.     }
  36.  
  37.     public HBox addHBox(){
  38.         HBox hbox = new HBox();
  39.         hbox.setPadding(new Insets(15, 12, 15, 12));
  40.         hbox.setSpacing(10);
  41.         hbox.setStyle("-fx-background-color: #336699;");
  42.  
  43.         return hbox;
  44.     }
  45.  
  46.     public GridPane addGridPane(){
  47.  
  48.         GridPane grid = new GridPane();
  49.         grid.setHgap(10);
  50.         grid.setVgap(10);
  51.         grid.setPadding(new Insets(0,10,0,10));
  52.  
  53.         //monday
  54.         StackPane mondayStack = new StackPane();
  55.  
  56.             Rectangle moRect = new Rectangle(30,70);
  57.             moRect.setArcHeight(10);
  58.             moRect.setArcWidth(10);
  59.             moRect.setFill(Color.DARKSLATEBLUE);
  60.  
  61.             Text moText = new Text("Mo");
  62.             moText.setFont(Font.font("Arial", FontPosture.ITALIC, 14));
  63.             moText.setFill(Color.WHEAT);
  64.             moText.setTextAlignment(TextAlignment.RIGHT);
  65.  
  66.         mondayStack.getChildren().addAll(moRect, moText);
  67.         grid.add(mondayStack, 1, 1);
  68.  
  69.         //tuesday
  70.         StackPane tuesdayStack = new StackPane();
  71.  
  72.             Rectangle tuRect = new Rectangle(30,70);
  73.             tuRect.setArcHeight(10);
  74.             tuRect.setArcWidth(10);
  75.             tuRect.setFill(Color.DARKSLATEBLUE);
  76.  
  77.             Text tuText = new Text("Tu");
  78.             tuText.setFont(Font.font("Arial", FontPosture.ITALIC, 14));
  79.             tuText.setFill(Color.WHEAT);
  80.             tuText.setTextAlignment(TextAlignment.RIGHT);
  81.  
  82.         tuesdayStack.getChildren().addAll(tuRect, tuText);
  83.         grid.add(tuesdayStack, 1, 2);
  84.  
  85.         //wednesday
  86.         StackPane wednesdayStack = new StackPane();
  87.             Rectangle weRect = new Rectangle(30,60);
  88.             weRect.setArcHeight(10);
  89.             weRect.setArcWidth(10);
  90.             weRect.setFill(Color.DARKSLATEBLUE);
  91.  
  92.             Text weText = new Text("We");
  93.             weText.setFont(Font.font("Arial", FontPosture.ITALIC, 14));
  94.             weText.setFill(Color.WHEAT);
  95.             weText.setTextAlignment(TextAlignment.RIGHT);
  96.         wednesdayStack.getChildren().addAll(weRect, weText);
  97.         grid.add(wednesdayStack, 1, 3);
  98.  
  99.         //thursday
  100.         StackPane thursdayStack = new StackPane();
  101.             Rectangle thRect = new Rectangle(30,50);
  102.             thRect.setArcHeight(10);
  103.             thRect.setArcWidth(10);
  104.             thRect.setFill(Color.DARKSLATEBLUE);
  105.  
  106.             Text thText = new Text("Th");
  107.             thText.setFont(Font.font("Arial", FontPosture.ITALIC, 14));
  108.             thText.setTextAlignment(TextAlignment.RIGHT);
  109.             thText.setFill(Color.WHEAT);
  110.         thursdayStack.getChildren().addAll(thRect, thText);
  111.         grid.add(thursdayStack, 1, 4);
  112.  
  113.         return grid;
  114.     }
  115.  
  116.     public VBox addVBox(){
  117.  
  118.         VBox vBox = new VBox();
  119.         vBox.getChildren().addAll( addHBox() , addGridPane());
  120.         return vBox;
  121.     }
  122.  
  123.  
  124.     public static void main(String[] args) {
  125.  
  126.         launch(args);
  127.     }
  128. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top