更具体地说,为什么我的JavaFX控件没有居中?这是两个截图,第一个刚开始之后(我将窗口移动到一个更明显的位置,但还没有调整大小),第二个是在调整它以显示我的问题之后.如果你帮我确认它的大小(在所有DPI上),当它第一次显示时,奖励积分:

方便地,相关代码包含在那些屏幕截图中.如果您仍然需要它作为文本,请转到:
private void initJFXPanel(JFXPanel holder)
{
{
{
rootGrid = new GridPane();
rootGrid.setAlignment(Pos.CENTER);
rootGrid.setPadding(new Insets(16));
rootGrid.setHgap(16);
rootGrid.setVgap(8);
}
interior = holder.getScene();
if (interior == null)
holder.setScene(interior = new Scene(rootGrid));
interior.setRoot(rootGrid);
}
{
statusLabel = new Label("Checking for Updates...");
statusLabel.setAlignment(Pos.CENTER);
statusLabel.setTextAlignment(TextAlignment.CENTER);
rootGrid.add(statusLabel, 0, 0);
}
{
progressBar = new ProgressBar();
progressBar.setProgress(-1);
progressBar.setPrefWidth(Constants.MAX_WIN_BOUNDS.width / 5d); // 1/5 the width of the screen
rootGrid.add(progressBar, 0, 1);
}
{
downloadButton = new Button("Get it!");
downloadButton.setAlignment(Pos.CENTER);
rootGrid.add(downloadButton, 0, 2);
}
holder.setMinimumSize(new Dimension((int)(rootGrid.getPrefWidth() + .5), …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Javafx制作屏幕键盘进行布局.我正在使用Scene Builder制作FXML文件.
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="186.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
<children>
<VBox layoutX="0.0" layoutY="0.0" prefHeight="186.0" prefWidth="600.0" rotate="0.0" spacing="2.0">
<children>
<HBox minHeight="33.0" prefHeight="33.0" prefWidth="600.0" spacing="2.0">
<children>
<Label maxWidth="-Infinity" prefHeight="33.0" prefWidth="35.0" text="Milk" textAlignment="CENTER" />
<Label maxWidth="-Infinity" prefHeight="33.0" text="Mister" />
<Label maxWidth="-Infinity" prefHeight="35.0" text="Minimum" />
</children>
<padding>
<Insets left="5.0" />
</padding>
</HBox>
<HBox prefHeight="29.0" prefWidth="600.0">
<children>
<Button minWidth="29.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="29.0" text="Esc" textAlignment="CENTER" underline="false"> …Run Code Online (Sandbox Code Playgroud)