定位:桌面端开发。
- Stage:包含Title和Scene
- Scene 包含各种Pane(用FXML加载)
- Scene加载CSS
- CSS .root为根标签
- css可以在代码中加载,也可以在fxml中加载(stylesheets)
- styleClass可以表明元素所选择的类,可用逗号连接
FXML和Controller的绑定,可以在FXML的根元素中加fx:controller="sample.Controller"。
@FXML标签的变量名和xml文件中的fx:id名一样。
FXML中一般大写开头的代表类,小写开头的表示属性
fx:id 用来映射到Controller中的@Fxml实例
fx:controller 用来指定Contrller
fx:constant, factory, value用来构造实体对象。
eg:
fx:id
<String fx:value="Hello, World!"/>
<Double fx:value="1.0"/>
<Boolean fx:value="false"/>
fx:factory 用来构建没有constructor构造器的对象
<FXCollections fx:factory="observableArrayList">
<String fx:value="A"/>
<String fx:value="B"/>
<String fx:value="C"/>
</FXCollections>
implements Initializable 可以在Controler中实现初始化方法。
布局
- BorderPane:上下左右5个格子
- HBox:横向Pane
- VBox:纵向Pane
- StackPane:叠起来
- GridPane:格子
- FlowPane:瀑布流(排满了排下一个)
- TilePane:每一片一样大小
- AnchorPane:锚点
布局eg:
<GridPane alignment="CENTER" hgap="10.0" vgap="10.0"
xmlns:fx="http://javafx.com/fxml"
fx:controller="fxmltableview.FXMLTableViewController">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
<Label style="-fx-font: NORMAL 20 Tahoma;" text="Address Book"
GridPane.columnIndex="0" GridPane.rowIndex="0">
</Label>
<TableView fx:id="tableView" GridPane.columnIndex="0"
GridPane.rowIndex="1">
</TableView>
</GridPane>
网友评论