alignment => center, top_center, bottom_right.....etc.
<simple.fxml>
Basic GrindPane Layout.
Button 5개 추가. - 버튼들이 겹쳐서 나온다.
rowIndex, columnIndex을 추가하면 define한대로 나열된다.(index 0,0..)
( GrindPane default도 적용되면서> alignment = center, hgap= 10 pixel, vagp = 10pixel
// 버튼이 cetner에 위치하며 버튼 gap들이 10)
grindLinesVisible = "true" 추가해보자. (라인보이게 해보자)
> column 사이즈들은 글자수에 맞게 맞춰진다.
columnConstraints를 추가해보자. (column 사이즈를 바꿔보자.)
***순서 중요하다! 순서대로 적용되니.
columnConstraints percentWidth = "50.0" 추가해보자.
columnConstraints percentWidth = "50.0"
percent라 창의 50% 사이즈
총코드
<sample.fxml>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.layout.ColumnConstraints?>
<GridPane fx:controller="sample.Controller"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10"
gridLinesVisible="true">
<!--줄 보이게 추가-->
<columnConstraints>
<ColumnConstraints percentWidth="60"/> <!--순서 중요.-->
<ColumnConstraints percentWidth="40"/>
</columnConstraints>
<Button text = "Button One" GridPane.rowIndex="0" GridPane.ColumnIndex="0"/>
<Button text = "Button Two" GridPane.rowIndex="0" GridPane.ColumnIndex="1"/>
<Button text = "Button Three" GridPane.rowIndex="1" GridPane.ColumnIndex="0"/>
<Button text = "Button Long" GridPane.rowIndex="1" GridPane.ColumnIndex="1"/>
<Button text = "Button Five" GridPane.rowIndex="2" GridPane.ColumnIndex="0"/>
</GridPane>
<Main>
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
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")); // V
primaryStage.setTitle("Hello world");
primaryStage.setScene(new Scene(root, 700, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
<padding>
<insets top = "50/>" 추가 : 위로부터 간격 설정.
GridPane.columnSpan="2" 추가 -> button five의 columnIndex = 0 부터
cell내에서 alignment > GridPane.halignment = Right
총코딩
<simple.fxml>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.ColumnConstraints?>
<GridPane fx:controller="sample.Controller"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10"
gridLinesVisible="true">
<padding>
<Insets top="50" /> <!--위로부터 50 간격-->
</padding>
<!--<columnConstraints>-->
<!--<ColumnConstraints percentWidth="50.0"/>--> <!--column사이즈-->
<!--<ColumnConstraints percentWidth="50.0"/>-->
<!--</columnConstraints>-->
<Button text="Button One" GridPane.rowIndex="0" GridPane.columnIndex="0"
GridPane.halignment="RIGHT"/>/> <!--cell내에서 이동-->
<Button text="Button Two" GridPane.rowIndex="0" GridPane.columnIndex="1"/>
<Button text="Button Three" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
<Button text="Really Long Button Four " GridPane.rowIndex="1" GridPane.columnIndex="1"/>
<Button text="Button Five" GridPane.rowIndex="2" GridPane.columnIndex="0"
GridPane.columnSpan="2"/>
</GridPane>
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);
}
}
'JavaCode(review)' 카테고리의 다른 글
java fx - BorderPane Layout (0) | 2020.07.21 |
---|---|
java fx - Hbox Layout (0) | 2020.07.21 |
java fx - 글쓰기, 글색/진하게/크기 변경 등. (0) | 2020.07.20 |
collections challenge 종합 (0) | 2020.07.17 |
Map.entry -collections / unmodifiable Map (0) | 2020.07.16 |