我选择了一个窗格,但我想设置对齐方式,可以吗?
I have chosen a Pane, but I would like to set the alignment, is it possible?
我正在用 javafx 做一个项目。作为 cointainer,我选择 Pane,这可能是最糟糕的决定!是否可以使用根据面板大小加载的句子长度将文本居中?
我实际上是在展示我写的代码。如您所见,GeneralQuestion 的长度是多种多样的,问题没有最小或最大字符。如何根据面板的大小居中?
这是它的样子:
这是输出,您可以看到它没有居中。我知道有 VBox 或其他类型的面板,但我已经选择了这个,在更改所有内容之前,我想知道是否有任何方法可以让它看起来更好!
这是控制器:
public void nextQuest(ActionEvent e) throws IOException
{
secondaryImg.setVisible(false);
nextQuestionButton.setVisible(false);
getQuestion(cont);
cont++;
}
public void getQuestion(int cont) throws FileNotFoundException,
IOException
{
FileManager f = new FileManager();
numQuest();
QuestionManager m = new QuestionManager(f.loadQuestion());
GeneralQuestion.setText(m.getAllQuestion().get(cont).getBody());
answ=m.getAllQuestion().get(cont).getAnswer();
if(m.getAllQuestion().get(cont).getType().equals("normale")||m.getAllQuestion().get(cont).getType().equals("perditutto"))
answS.setVisible(true);
else if(m.getAllQuestion().get(cont).getType().equals("verofalso")){
RbVero.setVisible(true);
RbFalso.setVisible(true);
}
}
这是 FXML(的一部分):
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: #b8ffe0; -fx-border-width: 8px; -fx-border-color: #0e3d73;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="guiz.controller.GameScreenController">
<children>
<Label id="numquest" fx:id="numquest" layoutX="286.0" layoutY="35.0" text="Label">
<font>
<Font size="15.0" />
</font></Label>
<Label fx:id="GeneralQuestion" layoutX="225.0" layoutY="123.0" style="-fx-font-weight: 800;" text="Quest">
<font>
<Font size="18.0" />
</font>
</Label>
</children>
</Pane>
在 JavaFX 中,您可以通过将各种布局窗格相互嵌套来实现所需的布局。 Pane 确实是一个糟糕的决定,因为 Pane 根本不做任何布局。在您的情况下,VBox 确实是一个更好的选择,您可以将其放入 BorderPane。
我正在用 javafx 做一个项目。作为 cointainer,我选择 Pane,这可能是最糟糕的决定!是否可以使用根据面板大小加载的句子长度将文本居中?
我实际上是在展示我写的代码。如您所见,GeneralQuestion 的长度是多种多样的,问题没有最小或最大字符。如何根据面板的大小居中?
这是它的样子:
这是输出,您可以看到它没有居中。我知道有 VBox 或其他类型的面板,但我已经选择了这个,在更改所有内容之前,我想知道是否有任何方法可以让它看起来更好!
这是控制器:
public void nextQuest(ActionEvent e) throws IOException
{
secondaryImg.setVisible(false);
nextQuestionButton.setVisible(false);
getQuestion(cont);
cont++;
}
public void getQuestion(int cont) throws FileNotFoundException,
IOException
{
FileManager f = new FileManager();
numQuest();
QuestionManager m = new QuestionManager(f.loadQuestion());
GeneralQuestion.setText(m.getAllQuestion().get(cont).getBody());
answ=m.getAllQuestion().get(cont).getAnswer();
if(m.getAllQuestion().get(cont).getType().equals("normale")||m.getAllQuestion().get(cont).getType().equals("perditutto"))
answS.setVisible(true);
else if(m.getAllQuestion().get(cont).getType().equals("verofalso")){
RbVero.setVisible(true);
RbFalso.setVisible(true);
}
}
这是 FXML(的一部分):
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: #b8ffe0; -fx-border-width: 8px; -fx-border-color: #0e3d73;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="guiz.controller.GameScreenController">
<children>
<Label id="numquest" fx:id="numquest" layoutX="286.0" layoutY="35.0" text="Label">
<font>
<Font size="15.0" />
</font></Label>
<Label fx:id="GeneralQuestion" layoutX="225.0" layoutY="123.0" style="-fx-font-weight: 800;" text="Quest">
<font>
<Font size="18.0" />
</font>
</Label>
</children>
</Pane>
在 JavaFX 中,您可以通过将各种布局窗格相互嵌套来实现所需的布局。 Pane 确实是一个糟糕的决定,因为 Pane 根本不做任何布局。在您的情况下,VBox 确实是一个更好的选择,您可以将其放入 BorderPane。