본문 바로가기

JavaCode(review)

java fx - BorderPane Layout

반응형

most commnly used layouts ofr top-level windows.
borderPane.alignment 이용.

 

cf)Hbox Layout : 주로 child

 

예시) BorderPane Lyout - child : Hbox Layout


이미 borderPane의 <bottom>.....<\bottom>이라 top-right이 그냥 bottom-right으로 적용
bottom 안에hbox 넣어야 적용된다.

top위치에 글자 추가 Label text ..but alighnmnet center 적용 x

BorderPane.alignment 사용해야함.

 

 

 

정리코딩(옆 Output)

 

 

 

 

 

 

 

 

 

 

 

<sample.fxml>

<?import javafx.geometry.Insets?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.HBox?>

<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.control.Label?>
<BorderPane fx:controller="sample.Controller"
            xmlns:fx="http://javafx.com/fxml" > <!--여기에 다른 layout처럼 alignmet정의 불가> 오류 걸림.-->

    <top>                                       <!--위치 top에 글자추가 label text-->
        <Label text="This label is in the top position"
             BorderPane.alignment="CENTER"
             style = "-fx-border-color : red; -fx-border-width : 4; -fx-border-style:dashed "
            />
    </top>      <!--BorderPane.alignmnet이용 > top의 center로 -->
                 <!--border 설정 -->

    <bottom>                                            <!--위치 bottom-->
        <HBox spacing="10" alignment="bottom_right">    <!--위치 bottom_right-->
            <padding>
                <Insets bottom="10" right="10"/>        <!--창으로부터 gap-->
            </padding>
            <Button text="Okay" prefWidth="90"/>        <!--prefWidth 버튼사이트-->
            <Button text="Cancel" prefWidth="90"/>
            <Button text="Help" prefWidth="90"/>
        </HBox>
    </bottom>
</BorderPane>

Main

package sample;

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, 500, 275));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}