0
正如標題所暗示的那樣,當我更改javafx.scene.control.Label的文本時,它將調整包含在同一佈局中的所有組件的大小。我究竟如何防止這種情況?這裏是我的FXML標記:如何防止帶標籤的控件在更改其文本時調整其他組件的大小?
<?xml version="1.0" encoding="UTF-8"?>
<?language javascript?>
<?import org.think.software.test.javafx.view.login.LoginView?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.geometry.Insets?>
<LoginView fx:controller="org.think.software.test.javafx.view.login.LoginView"
xmlns:fx="http://think.org/software/test/javafx/login" alignment="CENTER"
hgap="10" vgap="10">
<padding>
<Insets top="35" right="35" bottom="35" left="35" />
</padding>
<Label fx:id="infoLabel" GridPane.columnIndex="0"
GridPane.rowIndex="0" GridPane.columnSpan="3" text="%infoLabelText" />
<Label fx:id="usernameLabel" GridPane.columnIndex="0"
GridPane.rowIndex="1" text="%usernameLabelText" />
<TextField fx:id="usernameField" GridPane.columnIndex="1"
GridPane.rowIndex="1" GridPane.columnSpan="2" promptText="%usernameFieldPromptText" />
<Label GridPane.columnIndex="0" GridPane.rowIndex="2"
text="%passwordLabelText" />
<PasswordField fx:id="passwordField"
GridPane.columnIndex="1" GridPane.rowIndex="2" GridPane.columnSpan="2"
promptText="%passwordFieldPromptText" />
<Button fx:id="loginButton" GridPane.columnIndex="0"
GridPane.rowIndex="3" GridPane.columnSpan="3"
onAction="java.lang.System.out.println(infoLabel.setText('Logging in...'));"
text="%loginButtonText" />
</LoginView>
@Gemtastic,我從Oracle提供的參考指南中學習了FXML。我爲測試目的定義了onAction屬性。 –
@Gemtastic實際上,LoginView是我定義的類。它擴展了我定義的另一個類View。 View因此擴展了GridPane。原因是爲了防止重寫代碼,因爲我希望我的應用程序的所有佈局共享一個控制「縮放」系統。如果這有什麼意義......截至目前,View/LoginView實際上沒有顯示代碼。View只是擴展了GridPane,LoginView是控制器/演示者。 –
@Gemtastic Nope,你介意提供一個代碼示例嗎? –