【发布时间】:2014-08-20 14:33:51
【问题描述】:
我正在尝试使跨越 GridPane 两列的标签居中。但是,它似乎不起作用。
应用类:
public class GUIMainFXML extends Application {
@Override
public void start(Stage primaryStage) {
try {
GridPane p = (GridPane) FXMLLoader.load(getClass().getResource(
"FirstGUIexample.fxml"));
Scene scene = new Scene(p);
scene.getStylesheets().add(
getClass().getResource("application.css").toExternalForm());
primaryStage.setTitle("Welcome (FXML CODE)");
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}}
fxml 文件:
<GridPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
hgap="5" vgap="5">
<padding>
<Insets top="10" right="10" bottom="10" left="10" />
</padding>
<children>
<Text text="Welcome" GridPane.columnSpan="2" GridPane.halignment="CENTER"
GridPane.rowIndex="0" />
<Button text="Press me" GridPane.halignment="CENTER"
GridPane.rowIndex="1" GridPane.columnSpan="2" />
<CheckBox text="Don't touch me" GridPane.rowIndex="2"
GridPane.halignment="CENTER" GridPane.columnSpan="2" />
<Label text="Type me: " GridPane.halignment="CENTER"
GridPane.columnIndex="1" GridPane.rowIndex="3" />
<TextField GridPane.rowIndex="3" GridPane.columnIndex="2"
GridPane.halignment="CENTER" />
</children>
</GridPane>
应用程序.css
Text {
-fx-font-size: 15pt;
-fx-font-family: Tahoma;
-fx-font-weight: bold;
}
我想在css或fxml中设置它,我只是在测试。
【问题讨论】:
标签: javafx