【发布时间】:2021-10-23 06:11:38
【问题描述】:
我正在创建一个贷款计算器,但现在确定如何对齐流程窗格的位置,以便所有内容都居中,因为它目前是倾斜的。
public class Main extends Application {
private HBox hboxAnnualIntRate = new HBox(lbAnnualIntRate,tfAnnualInterestRate);
private HBox hboxNumberOfYears = new HBox(lbNumberOfYears,tfNumberOfYears);
private HBox hboxLoanAmount = new HBox(lbLoanAmount,tfLoanAmount);
private HBox hboxMonthlyPayment = new HBox(lbMonthlyPayment,tfMonthlyPayment);
private HBox hboxTotalPayment = new HBox(lbTotalPayment,tfTotalPayment);
@Override
public void start(Stage primaryStage) throws Exception{
primaryStage.setTitle("Loan Calculator");
FlowPane rootNode = new FlowPane(20,20);
rootNode.setAlignment(Pos.CENTER);
Scene scene = new Scene (rootNode, 500, 300);
primaryStage.setScene(scene);
calculateButton.setOnAction(actionEvent -> {
calculatePayment();
});
rootNode.getChildren().addAll(hboxAnnualIntRate,hboxNumberOfYears,hboxLoanAmount,hboxMonthlyPayment,hboxTotalPayment,calculateButton);
primaryStage.show();
}
【问题讨论】:
-
这些行居中。拿出尺子,在中间划一条线,然后测量左右。
-
在此处使用反引号而不是直引号格式化您的代码。并在顶部 和 底部使用三次反引号。我在这里为你解决了这个问题。
-
可能是
GridPane,如Aligning Content & Centering the Grid所示。
标签: java user-interface javafx