JAVAFX
FlowPane布局
Flowpane是一个容器。它在一行上排列连续的子组件,并且如果当前行填充满了以后,则自动将子组件向下推到一行
public class FlowPanedemo extends Application {
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("FlowPanedemo");
FlowPane flowPane = new FlowPane();
//设置控件的垂直水平间距
flowPane.setHgap(10);
flowPane.setVgap(10);
Button button1 = new Button("button1");
Button button2 = new Button("button2");
button2.setPrefSize(100,100);
Text text = new Text();
text.setText("hello world");
text.setFill(Color.RED);
//复选框
CheckBox checkBox = new CheckBox();
checkBox.setText("123");
RadioButton radioButton = new RadioButton();
radioButton.setText("radiobuttion");
TextField textField = new TextField();
textField.setText("111");
flowPane.getChildren().addAll(button1,button2,text,checkBox,radioButton,textField);
Scene scene = new Scene(flowPane,500,300);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
HBox水平布局
边框样式:
1. border-style边框样式(hidden隐藏、none无边框、dotted电线、dashed虚线、soild实线、double两个边框、groove3D沟槽边框、ridge3D脊边框、inset3D嵌入边框、outset3D突出边框)
缩写:
①border-style: 上 右 下 左;
②border-style: 上 左右 下;
③border-style: 上下 左右;
④border-style: 上下左右;
border-width边框宽度(5px、medium):可以单独设置一边的宽度。
border-top-width上边框、border-bottom-width下边框、border-right-width有边框、border-left-width左边框。
border-color边框颜色: 可以单独设置一边的颜色。
border-top-color、border-bottom-color、border-right-color、border-left-color
缩写:
①border: 5px solid red;
②border-top:5px solid red ;
③border-bottom:5px solid red ;
④border-right:5px solid red ;
⑤border-left:5px solid red ;
轮廓
轮廓样式:轮廓是在边框外面的一层,其用法同边框。
outline-style
outline-color
outline-width
缩写:outline:green dotted thick ;
边距
边距:(百分数、em、px)
margin-top
margin-bottom
margin-right
margin-left
缩写:margin: 上 右 下 左;
填充
填充:(百分数、em、px)
padding-top
padding-bottom
padding-left
padding-right
缩写:padding: 上 右 下 左;
尺寸
尺寸:(百分数、em、px)
包括height、width
height、max-height、min-height
width、max-width、min-width
//设置控件间的间距
hbox.setSpacing(10);
//设置内边距
Hbox.setPadding(new Insets(10));
//设置某个组件的边距
Hbos.setMargin(b1,new Insets(10))
//设置水平居中方式
Hbox.setAlignment(Pos.CENTER);
案例
public class HBoxDemo extends Application {
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("HBoxDemo");
Group group = new Group();
//创建水平布局
HBox hbox = new HBox();
//配置背后颜色
hbox.setStyle("-fx-background-color: #336699;");
hbox.setMinWidth(300);
hbox.setMinHeight(50);
group.getChildren().add(hbox);
//设置控件间的间距
hbox.setSpacing(10);
Button button = new Button();
button.setText("确定");
Text text = new Text();
text.setText("hello");
text.setFont(Font.font("宋体",30));
//Insets:设置偏移量 上右下左
hbox.setMargin(button,new Insets(10,0,0,0));
hbox.setMargin(text,new Insets(10,0,0,0));
hbox.getChildren().addAll(button,text);
Scene scene = new Scene(group,500,400);
stage.setScene(scene);
stage.show();
}
public static void main(String[]