Skip to content

Instantly share code, notes, and snippets.

@MaciejDobrowolski
Created August 1, 2016 09:49
Show Gist options
  • Save MaciejDobrowolski/0111f8f1b9af590322db51e3f67325b6 to your computer and use it in GitHub Desktop.
Save MaciejDobrowolski/0111f8f1b9af590322db51e3f67325b6 to your computer and use it in GitHub Desktop.
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<StackPane maxWidth="600.0" minHeight="-Infinity" prefWidth="600.0" style="-fx-border-color: black; -fx-border-width: 2px;" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label text="This is StackPane" StackPane.alignment="TOP_LEFT">
<StackPane.margin>
<Insets />
</StackPane.margin>
</Label>
<HBox maxHeight="-Infinity" maxWidth="600.0" minHeight="-Infinity" minWidth="-Infinity" prefWidth="600.0" spacing="500.0" style="-fx-border-width: 2px; -fx-border-color: red;" StackPane.alignment="CENTER">
<children>
<Label text="This is HBox (parent=StackPane) with maxWidth = 600" />
</children>
</HBox>
<AnchorPane maxWidth="600.0" prefHeight="150.0" prefWidth="600.0" style="-fx-border-color: green; -fx-border-width: 2px;">
<children>
<Label text="This is AnchorPane (parent=StackPane) with maxWidth = 600" />
<Label layoutX="491.0" layoutY="54.0" text="This label has left anchor = 700" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="700.0" />
</children>
<StackPane.margin>
<Insets bottom="40.0" top="40.0" />
</StackPane.margin>
</AnchorPane>
</children>
</StackPane>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment