GUI( JavaFX Scene Builder )/Layout
AnchorPane
by pms93
2022. 8. 15.
package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class AnchorPanes extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Button[] buttons = new Button[4];
String[] strings = {"TOP", "LEFT", "RIGHT", "BOTTOM"};
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new Button(strings[i]);
}
// .set_location_Anchor(Node, doule);
// - Node를 location으로부터 double만큼 이격시켜준다.
AnchorPane.setTopAnchor(buttons[0], 10.0);
AnchorPane.setLeftAnchor(buttons[1], 20.0);
AnchorPane.setRightAnchor(buttons[2], 30.0);
AnchorPane.setBottomAnchor(buttons[3], 40.0);
AnchorPane ap = new AnchorPane();
ap.getChildren().addAll(buttons[0], buttons[1], buttons[2], buttons[3]);
primaryStage.setScene(new Scene(ap, 500, 250));
primaryStage.show();
}
}