我正在使用javafx在eclipse中创建登录表单和注册表单...当应用程序运行时,它显示登录和注册表单的默认大小..两个表单都有不同的大小..如何更新它?
代码如下
Samplecontroller.java
public void signin() {
AnchorPane pane2;
try {
pane2 = FXMLLoader.load(getClass().getResource("Login.fxml"))
root.getChildren().setAll(pane2);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
FXML
<AnchorPane prefHeight="435.0" prefWidth="655.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
<children>
<ImageView fitHeight="435.0" fitWidth="655.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../image/reg1.jpeg" />
</image>
</ImageView>
<Label layoutX="278.0" layoutY="72.0" prefHeight="22.0" prefWidth="212.0" text="Login" textFill="#f8f7f7">
<font>
<Font name="Arial Bold Italic" size="39.0" />
</font>
</Label>
<Label layoutX="38.0" layoutY="229.0" text="Email id" textFill="#19f236">
<font>
<Font name="System Bold" size="28.0" />
</font>
</Label>
<Label layoutX="38.0" layoutY="309.0" text="Login id" textFill="#19f236">
<font>
<Font name="System Bold" size="22.0" />
</font>
</Label>
<TextField layoutX="204.0" layoutY="237.0" prefHeight="25.0" prefWidth="326.0" />
<TextField layoutX="209.0" layoutY="313.0" prefHeight="25.0" prefWidth="326.0" />
<Button layoutX="252.0" layoutY="374.0" mnemonicParsing="false" text="Login" />
<Button layoutX="428.0" layoutY="374.0" mnemonicParsing="false" text="Cancel" />
<Label layoutX="52.0" layoutY="357.0" textFill="#ee1111">
<font>
<Font size="28.0" />
</font>
</Label>
并在主要班级
public void start(Stage primaryStage) {
try {
AnchorPane root = (AnchorPane)FXMLLoader.load(getClass().getResource("Sample.fxml"));
Scene scene = new Scene(root,300,300);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
答案 0 :(得分:1)
在主类中,您将场景宽度和高度设置为300,它将覆盖启动时在fxml文件中设置的高度和宽度。 所以我建议你只设置根到场景
Scene scene = new Scene(root);
这将允许从fxml文件中获取高度和宽度