gpt4 book ai didi

JavaFX:为什么 HBox 不将控件排列在单个水平行中?如何解决这个错误并使 HBox 做应该做的事情?

转载 作者:行者123 更新时间:2023-12-01 09:50:51 28 4
gpt4 key购买 nike

HBox 是一个容器组件,用于在一条水平线上保留和排列控件。然而,我在我的应用程序中的许多 HBox 容器之一中遇到了控件的“困惑”放置,并且该放置绝对不像水平线,而且,包含在 HBox 中的控件与 HBox 中未包含的其他控件混淆。

放置在 SceneBuilder 中看起来很好,即使在 SceneBuilder 预览窗口中看起来也很好,但是,当 FXML 加载到我的应用程序中时它会有所不同。我的代码不包含任何位置修改 - 除了有问题的 HBox 中的几个控件之外,所有代码均已渲染并准确放置在 FXML 文件应有的位置。

应用程序设计和 SceneBuilder 预览如下所示:

SceneBuilder design of my app and SceneBuilder preview

全部按预期显示并对应于 FXML 结构。

但是,当 FXML 在我的应用程序中加载时,其中一个 HBox 显示困惑(尽管 FXML 中的结构与上面的 HBox 类似,显示 OK):

Real application based on the FXML with a chaotic placement of controls

有些事情在我的头顶上:

  • HBox 如何垂直而不是水平排列控件?
  • 未包含在 HBox 中的其他控件(文本字段)如何显示包含在 HBox 中的 BETWEEN 控件?
  • SceneBuilder 中的预览与真实应用程序有何不同?预览是否与我的应用程序中的 JavaFX 运行时中的 FXML 解释不同有关?
  • 当 FXML 中具有(几乎)相同的结构时,为什么有些 HBox 工作正常而另一些则不行(即使我重用/copy+paste/上面工作正常的 HBox,HBox 的问题仍然存在)。

我在谷歌上搜索了 HBox 和 JavaFX 中的现有错误,但没有找到任何可能有助于解决此问题的内容。我什至不知道如何从我的代码中纠正这个困惑。

我怎样才能防止这种情况发生或解决或至少解决问题?感谢任何人的建议!

我的 FXML 在这里(我在这篇文章中省略了其他选项卡的内容):

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.text.*?>
<?import javafx.scene.image.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<AnchorPane fx:id="rootAnchorPane" maxHeight="400.0" maxWidth="650.0" minHeight="400.0" minWidth="650.0" prefHeight="400.0" prefWidth="650.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="cz.oksystem.oksmart3calc.gui.OKsmart3CalculatorController">
<children>
<HBox maxHeight="60.0" maxWidth="650.0" minHeight="60.0" minWidth="650.0" prefHeight="60.0" prefWidth="650.0" AnchorPane.bottomAnchor="340.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<HBox maxHeight="60.0" maxWidth="530.0" minHeight="60.0" minWidth="530.0" prefHeight="60.0" prefWidth="530.0">
<children>
<ImageView fx:id="chipImage" disable="true" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@/image_chip.png" />
</image>
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</HBox.margin>
<viewport>
<Rectangle2D height="40.0" width="46.0" />
</viewport>
</ImageView>
<VBox>
<children>
<Label fx:id="calcTitle" maxWidth="470.0" minWidth="470.0" prefWidth="470.0" text="OKsmart 3 Calculator" textFill="#009646">
<font>
<Font name="System Bold" size="25.0" />
</font>
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="10.0" />
</HBox.margin>
<VBox.margin>
<Insets top="1.0" />
</VBox.margin>
</Label>
<Label fx:id="statusLineLabel" alignment="CENTER" contentDisplay="CENTER" maxWidth="470.0" minWidth="470.0" prefWidth="470.0" textAlignment="CENTER" />
</children>
</VBox>
</children>
</HBox>
<VBox>
<children>
<HBox>
<children>
<RadioButton fx:id="langCeskyRadioBtn" maxWidth="70.0" minWidth="70.0" mnemonicParsing="false" onKeyReleased="#langCeskyRadioBtnKeySelected" onMouseClicked="#langCeskyRadioBtnMouseSelected" prefWidth="70.0" selected="true" text="Česky">
<toggleGroup>
<ToggleGroup fx:id="langRadioBtnGroup" />
</toggleGroup>
<VBox.margin>
<Insets top="10.0" />
</VBox.margin>
</RadioButton>
<ImageView pickOnBounds="true" preserveRatio="true">
<HBox.margin>
<Insets top="2.0" />
</HBox.margin>
<image>
<Image url="@/vlajka_cr_21.png" />
</image>
<viewport>
<Rectangle2D height="13.0" width="21.0" />
</viewport>
</ImageView>
</children>
<VBox.margin>
<Insets top="10.0" />
</VBox.margin>
</HBox>
<HBox>
<children>
<RadioButton fx:id="langAnglickyRadioBtn" maxWidth="70.0" minWidth="70.0" mnemonicParsing="false" onKeyReleased="#langAnglickyRadioBtnKeySelected" onMouseClicked="#langAnglickyRadioBtnMouseSelected" prefWidth="70.0" text="Anglicky" toggleGroup="$langRadioBtnGroup">
<VBox.margin>
<Insets top="5.0" />
</VBox.margin>
</RadioButton>
<ImageView pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@/vlajka_en_21.png" />
</image>
<HBox.margin>
<Insets top="2.0" />
</HBox.margin>
<viewport>
<Rectangle2D height="13.0" width="21.0" />
</viewport>
</ImageView>
</children>
<VBox.margin>
<Insets bottom="5.0" top="5.0" />
</VBox.margin>
</HBox>
</children>
<HBox.margin>
<Insets left="20.0" right="10.0" />
</HBox.margin>
</VBox>
</children>
</HBox>
<TabPane fx:id="calculatorTabPane" layoutY="60.0" maxHeight="340.0" maxWidth="650.0" minHeight="340.0" minWidth="650.0" prefHeight="340.0" prefWidth="650.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="60.0">
<tabs>
<Tab fx:id="unblockCardTab" closable="false" onSelectionChanged="#unblockTabSelected" text="Odblokování karty">
<content>
<VBox fx:id="uc_unblockTabVBox" maxHeight="310.0" maxWidth="650.0" minHeight="310.0" minWidth="650.0" prefHeight="310.0" prefWidth="650.0">
<children>
<HBox maxWidth="650.0" minWidth="650.0" prefWidth="650.0">
<children>
<VBox fx:id="uc_labelsVBox" maxWidth="220.0" minWidth="220.0" prefWidth="220.0">
<children>
<Label fx:id="uc_unblockTypeLabel" text="Způsob odblokování:">
<VBox.margin>
<Insets bottom="8.0" left="10.0" right="5.0" top="10.0" />
</VBox.margin>
</Label>
<Label fx:id="uc_ublockKeyLabel" text="Klíč pro odblokování:">
<VBox.margin>
<Insets bottom="8.0" left="10.0" right="5.0" top="5.0" />
</VBox.margin>
</Label>
<Label fx:id="uc_challengeLabel" text="Výzva (challenge):">
<VBox.margin>
<Insets bottom="8.0" left="10.0" right="5.0" top="5.0" />
</VBox.margin>
</Label>
<Label fx:id="uc_serialNoLabel" text="Sériové číslo karty (UID):">
<VBox.margin>
<Insets bottom="8.0" left="10.0" right="5.0" top="5.0" />
</VBox.margin>
</Label>
<Label fx:id="uc_pwdKeyStoreLabel" text="Heslo úložiště klíčů pro odblokování:">
<VBox.margin>
<Insets bottom="8.0" left="10.0" right="5.0" top="5.0" />
</VBox.margin>
</Label>
<Label fx:id="uc_cardReaderLabel" text="Čtečka karet:">
<VBox.margin>
<Insets bottom="7.0" left="10.0" right="5.0" top="5.0" />
</VBox.margin>
</Label>
<Label fx:id="uc_newPinLabel" text="Nový PIN:">
<VBox.margin>
<Insets bottom="7.0" left="10.0" right="5.0" top="5.0" />
</VBox.margin>
</Label>
<Label fx:id="uc_newPinVerifyLabel" text="Ověření nového PINu:">
<VBox.margin>
<Insets bottom="7.0" left="10.0" right="5.0" top="5.0" />
</VBox.margin>
</Label>
</children>
</VBox>
<VBox fx:id="uc_controlsVBox" maxWidth="430.0" minWidth="430.0" prefWidth="430.0">
<children>
<HBox maxWidth="415.0" minWidth="415.0" prefWidth="415.0">
<children>
<RadioButton fx:id="uc_remoteRadioBtn" maxHeight="25.0" maxWidth="205.0" minHeight="25.0" minWidth="205.0" mnemonicParsing="false" onKeyReleased="#uc_remoteRadioBtnKeySelect" onMouseClicked="#uc_remoteRadioBtnMouseClicked" prefHeight="25.0" prefWidth="205.0" selected="true" text="Vzdálené (výpočet odezvy)">
<toggleGroup>
<ToggleGroup fx:id="uc_radioBtnGroup" />
</toggleGroup>
<HBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</RadioButton>
<RadioButton fx:id="uc_localRadioBtn" maxHeight="25.0" maxWidth="205.0" minHeight="25.0" minWidth="205.0" mnemonicParsing="false" onKeyReleased="#uc_localRadioBtnKeySelect" onMouseClicked="#uc_localRadioBtnMouseClicked" prefHeight="25.0" prefWidth="205.0" text="Lokální (máte k dispozici kartu)" toggleGroup="$uc_radioBtnGroup">
<HBox.margin>
<Insets right="10.0" top="5.0" />
</HBox.margin>
</RadioButton>
</children>
</HBox>
<ChoiceBox fx:id="uc_keyChoiceBox" maxHeight="25.0" maxWidth="415.0" minHeight="25.0" minWidth="415.0" prefHeight="25.0" prefWidth="415.0">
<VBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</ChoiceBox>
<TextField fx:id="uc_challengeTextField" maxHeight="25.0" maxWidth="415.0" minHeight="25.0" minWidth="415.0" onKeyReleased="#uc_challengeTextFieldChanged" prefHeight="25.0" prefWidth="415.0">
<VBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</TextField>
<TextField fx:id="uc_serialNoTextField" maxHeight="25.0" maxWidth="415.0" minHeight="25.0" minWidth="415.0" onKeyReleased="#uc_serialNoTextFieldChanged" prefHeight="25.0" prefWidth="415.0">
<VBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</TextField>
<HBox fx:id="uc_pwdHbox">
<children>
<PasswordField fx:id="uc_pwdKeyStorePwdField" maxHeight="25.0" maxWidth="385.0" minHeight="25.0" minWidth="385.0" onKeyReleased="#uc_pwdKeyStorePwdFieldChanged" prefHeight="25.0" prefWidth="385.0">
<VBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</VBox.margin>
<HBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</PasswordField>
<Button fx:id="uc_pwdPreviewButton" maxHeight="25.0" maxWidth="25.0" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onMousePressed="#uc_previewPwdButtonMousePressed" onMouseReleased="#uc_previewPwdButtonMouseReleased" prefHeight="25.0" prefWidth="25.0">
<graphic>
<ImageView pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@/eye-simple.png" />
</image>
<viewport>
<Rectangle2D height="20.0" width="20.0" />
</viewport>
</ImageView>
</graphic>
<HBox.margin>
<Insets right="10.0" top="5.0" />
</HBox.margin>
</Button>
</children>
</HBox>
<ChoiceBox fx:id="uc_cardReaderChoiceBox" maxHeight="25.0" maxWidth="415.0" minHeight="25.0" minWidth="415.0" prefHeight="25.0" prefWidth="415.0">
<VBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</ChoiceBox>
<HBox>
<children>
<PasswordField fx:id="uc_newPinPwdField" maxHeight="25.0" maxWidth="385.0" minHeight="25.0" minWidth="385.0" onKeyReleased="#uc_newPinTextFieldChanged" prefHeight="25.0" prefWidth="385.0">
<VBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</VBox.margin>
<HBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</PasswordField>
</children>
<VBox.margin>
<Insets />
</VBox.margin>
</HBox>
<HBox fx:id="uc_pwdHbox1">
<children>
<PasswordField fx:id="uc_newPinVerifyPwdField" maxHeight="25.0" maxWidth="385.0" minHeight="25.0" minWidth="385.0" onKeyReleased="#uc_newPinVerifyTextFieldChanged" prefHeight="25.0" prefWidth="385.0" promptText="preview">
<HBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</HBox.margin>
<VBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</PasswordField>
<Button fx:id="uc_pwdPreviewButton1" maxHeight="25.0" maxWidth="25.0" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onMousePressed="#uc_previewPwdButtonMousePressed" onMouseReleased="#uc_previewPwdButtonMouseReleased" prefHeight="25.0" prefWidth="25.0" text="P">
<HBox.margin>
<Insets right="10.0" top="5.0" />
</HBox.margin>
</Button>
</children>
</HBox>
</children>
</VBox>
</children>
</HBox>
<VBox maxWidth="650.0" minWidth="650.0" prefWidth="650.0" VBox.vgrow="ALWAYS">
<children>
<GridPane VBox.vgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="170.0" minWidth="170.0" prefWidth="170.0" />
<ColumnConstraints hgrow="SOMETIMES" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="170.0" minWidth="170.0" prefWidth="170.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="100.0" minHeight="2.0" valignment="TOP" vgrow="ALWAYS" />
<RowConstraints maxHeight="25.0" minHeight="25.0" prefHeight="25.0" valignment="CENTER" vgrow="NEVER" />
<RowConstraints maxHeight="100.0" minHeight="5.0" valignment="BOTTOM" vgrow="ALWAYS" />
</rowConstraints>
<children>
<Button fx:id="uc_unblockButton" maxHeight="25.0" maxWidth="310.0" minHeight="25.0" minWidth="310.0" mnemonicParsing="false" onKeyReleased="#uc_unblockButtonKeyFired" onMouseClicked="#uc_unblockButtonMouseClicked" prefHeight="25.0" prefWidth="310.0" text="Vypočíst odezvu" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<VBox GridPane.columnIndex="1" GridPane.vgrow="ALWAYS" />
<VBox GridPane.columnIndex="1" GridPane.rowIndex="2" GridPane.vgrow="ALWAYS" />
</children>
</GridPane>
</children>
</VBox>
<HBox fx:id="uc_responseHBox" maxWidth="650.0" minWidth="650.0" prefWidth="650.0">
<children>
<Label fx:id="uc_responseLabel" prefWidth="210.0" text="Odezva (response):">
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="5.0" top="8.0" />
</HBox.margin>
</Label>
<TextField fx:id="uc_responseTextField" maxHeight="25.0" maxWidth="415.0" minHeight="25.0" minWidth="415.0" prefHeight="25.0" prefWidth="415.0">
<HBox.margin>
<Insets bottom="10.0" right="5.0" top="2.0" />
</HBox.margin>
</TextField>
</children>
</HBox>
</children>
</VBox>
</content>
</Tab>
<Tab fx:id="keyStoreTab" closable="false" onSelectionChanged="#keyStoreTabSelected" text="Správa klíčů pro odblokování">
</Tab>
</tabs>
</TabPane>
</children>
</AnchorPane>

我的加载代码在这里:

public class Main extends Application {

@Override
public void start(Stage primaryStage) {
try {

FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getClassLoader().getResource("cz/oksystem/oksmart3calc/gui/OKsmart3Calculator.fxml"),
OKsmart3CalculatorController.messages);
AnchorPane root = (AnchorPane) fxmlLoader.load();
Scene scene = new Scene(root);
scene.getStylesheets().add(
getClass().getClassLoader().getResource("cz/oksystem/oksmart3calc/gui/application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("OKsmart 3 Calculator");
primaryStage.show();
primaryStage.setResizable(false);
primaryStage.sizeToScene();
Platform.setImplicitExit(false);
final OKsmart3CalculatorController oksmart3CalculatorController = (OKsmart3CalculatorController) fxmlLoader
.getController();
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {

@Override
public void handle(WindowEvent event) {
boolean neededConfirmation = oksmart3CalculatorController.deleteUnsavedRecordsConfirmation(event);
if (!neededConfirmation || oksmart3CalculatorController.isConfirmedByUser()) {
oksmart3CalculatorController.saveSettings();
oksmart3CalculatorController.cardManagerProviderShutdown();
Platform.exit();
}
event.consume();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
launch(args);
}

}

最佳答案

感谢您的评论。我最终意识到我所描述的行为的可能原因,然后我通过实验确认并修复了它。

当我声称我不会修改代码中控件的位置时,这是半真半假的。我根据顶部单选按钮的状态动态地从其父控件中删除控件或将控件添加到其父控件中,因为并非所有控件都具有共同意义。在单选按钮“Lokální”(本地)和“Vzdálené”(远程)之间切换会更改以下控件的配置 - 根据本地与远程的选择,其中一些会出现,而另一些则会消失,这是所需的行为。我在下面的 Controller 类中提供了代码片段(修复后):

  @FXML
public void uc_remoteRadioBtnMouseClicked(MouseEvent event) {
System.out.println("Vzdalene mys...");
setVisibleRemoteUnblockControls(Key.KeyType.ADMIN_MASTER_KEY);
};

@FXML
public void uc_localRadioBtnMouseClicked(MouseEvent event) {
System.out.println("Lokalni mys...");
setVisibleLocalUnblockControls();
};

@FXML
public void uc_remoteRadioBtnKeySelect(KeyEvent event) {
System.out.println("Vzdalene klavesa...");
setVisibleRemoteUnblockControls(Key.KeyType.ADMIN_STATIC_KEY);
};

@FXML
public void uc_localRadioBtnKeySelect(KeyEvent event) {
System.out.println("Lokalni klavesa...");
setVisibleLocalUnblockControls();
};

private void setVisibleRemoteUnblockControls(Key.KeyType keyType) {
if (!uc_labelsVBox.getChildren().contains(uc_challengeLabel))
uc_labelsVBox.getChildren().add(uc_challengeLabel);
if (!uc_controlsVBox.getChildren().contains(uc_challengeTextField))
uc_controlsVBox.getChildren().add(uc_challengeTextField);
if (keyType.equals(Key.KeyType.ADMIN_STATIC_KEY)) {

uc_labelsVBox.getChildren().remove(uc_serialNoLabel);
uc_controlsVBox.getChildren().remove(uc_serialNoTextField);
} else {
if (!uc_labelsVBox.getChildren().contains(uc_serialNoLabel))
uc_labelsVBox.getChildren().add(uc_serialNoLabel);
if (!uc_controlsVBox.getChildren().contains(uc_serialNoTextField))
uc_controlsVBox.getChildren().add(uc_serialNoTextField);
}
uc_labelsVBox.getChildren().remove(uc_cardReaderLabel);
uc_labelsVBox.getChildren().remove(uc_newPinLabel);
uc_labelsVBox.getChildren().remove(uc_newPinVerifyLabel);
uc_controlsVBox.getChildren().remove(uc_cardReaderChoiceBox);
uc_controlsVBox.getChildren().remove(uc_pinHBox);
uc_controlsVBox.getChildren().remove(uc_pinVerifyHBox);

this.uc_unblockButton.setText(
this.uc_remoteRadioBtn.isSelected() ? messages.getString("OKsmart3Calculator.uc_unblockButtonRemote")
: messages.getString("OKsmart3Calculator.uc_unblockButtonLocal"));
if (!uc_unblockTabVBox.getChildren().contains(uc_responseHBox))
uc_unblockTabVBox.getChildren().add(uc_responseHBox);
if (true) {
printInfoStatus("Zadejte heslo, výzvu a vypočtěte odezvu.");
}

this.settingsStore.setProperty(UC_LOCALRADIOBTN, Boolean.valueOf(this.uc_localRadioBtn.isSelected()).toString());
}

private void setVisibleLocalUnblockControls() {
uc_labelsVBox.getChildren().remove(uc_challengeLabel);
uc_controlsVBox.getChildren().remove(uc_challengeTextField);
uc_labelsVBox.getChildren().remove(uc_serialNoLabel);
uc_controlsVBox.getChildren().remove(uc_serialNoTextField);
if (!uc_labelsVBox.getChildren().contains(uc_cardReaderLabel))
uc_labelsVBox.getChildren().add(uc_cardReaderLabel);
if (!uc_controlsVBox.getChildren().contains(uc_cardReaderChoiceBox))
uc_controlsVBox.getChildren().add(uc_cardReaderChoiceBox);
if (!uc_labelsVBox.getChildren().contains(uc_newPinLabel))
uc_labelsVBox.getChildren().add(uc_newPinLabel);
if (!uc_labelsVBox.getChildren().contains(uc_newPinVerifyLabel))
uc_labelsVBox.getChildren().add(uc_newPinVerifyLabel);
if (!uc_controlsVBox.getChildren().contains(uc_pinHBox))
uc_controlsVBox.getChildren().add(uc_pinHBox);
if (!uc_controlsVBox.getChildren().contains(uc_pinVerifyHBox))
uc_controlsVBox.getChildren().add(uc_pinVerifyHBox);

this.uc_unblockButton.setText(
this.uc_remoteRadioBtn.isSelected() ? messages.getString("OKsmart3Calculator.uc_unblockButtonRemote")
: messages.getString("OKsmart3Calculator.uc_unblockButtonLocal"));
uc_unblockTabVBox.getChildren().remove(uc_responseHBox);
if (true) {
printErrorStatus("Vložte kartu do čtečky...");
}

this.settingsStore.setProperty(UC_LOCALRADIOBTN, Boolean.valueOf(this.uc_localRadioBtn.isSelected()).toString());

}

当我将 uc_newPinVerifyPwdField 包装到新的 uc_pinVerifyHBox 中时,出现了问题,但忘记修改原始代码以添加/删除 uc_newPinVerifyPwdField 到/来自其父级。最初,uc_newPinVerifyPwdField 的父级是 uc_controlsVBox,但是,uc_newPinVerifyPwdField 不再是 uc_controlsVBox 的子级 - 它变成了一个子级uc_pinVerifyHBox 的。代码最初(修复之前)看起来像这样:

    uc_controlsVBox.getChildren().remove(uc_newPinVerifyPwdField);

    if (!uc_controlsVBox.getChildren().contains(uc_newPinVerifyPwdField))
uc_controlsVBox.getChildren().add(uc_newPinVerifyPwdField);

而不是当前的,正确的是:

    uc_controlsVBox.getChildren().remove(uc_pinVerifyHBox);

    if (!uc_controlsVBox.getChildren().contains(uc_pinVerifyHBox))
uc_controlsVBox.getChildren().add(uc_pinVerifyHBox);

看起来,它导致了控件渲染的困惑,现在工作正常。

关于JavaFX:为什么 HBox 不将控件排列在单个水平行中?如何解决这个错误并使 HBox 做应该做的事情?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37615139/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com