import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
/**
*
* @web http://zoranpavlovic.blogspot.com/
*/
public class AnchorPaneMain extends Application {
/**
* @param args
* the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("AnchorPane");
AnchorPane anchorpane = new AnchorPane();
// List should stretch as anchorpane is resized
ListView list = new ListView();
AnchorPane.setTopAnchor(list, 10.0);
AnchorPane.setLeftAnchor(list, 10.0);
AnchorPane.setRightAnchor(list, 85.0);
AnchorPane.setBottomAnchor(list, 10.0);
// Buttons will float on right edge
Button button1 = new Button("Button1");
AnchorPane.setTopAnchor(button1, 10.0);
AnchorPane.setRightAnchor(button1, 10.0);
Button button2 = new Button("Button2");
AnchorPane.setTopAnchor(button2, 40.0);
AnchorPane.setRightAnchor(button2, 10.0);
//Add list and buttons to AnchorPane
anchorpane.getChildren().addAll(list, button1, button2);
// Adding AnchorPane to the Scene
Scene scene = new Scene(anchorpane);
primaryStage.setScene(scene);
primaryStage.show();
}
}