如何在 JavaFXinputPane
中将我的面板居中?BorderPane
这是我的代码。
public class MainStage {
private Scene mainScene;
private InputPane inputPane;
private DisplayPane displayPane;
private EditPane editPane;
private BorderPane borderPane;
private VBox mainPane;
public MainStage(){
borderPane = new BorderPane();
inputPane=new InputPane();
displayPane=new DisplayPane();
editPane=new EditPane();
mainPane=new VBox();
mainPane.getChildren().addAll(inputPane.getPane(),displayPane.getTable(),editPane.getPane());
mainPane.setSpacing(10);
mainScene=new Scene(mainPane,800,480);
mainScene.getStylesheets().add("styleSheet.css");
}
public Scene getMainScene() {
return mainScene;
}
public InputPane getInputPane() {
return inputPane;
}
public DisplayPane getDisplayPane() {
return displayPane;
}
public EditPane getEditPane(){
return editPane;
}
}
我正在尝试修改InputPane
课程。
public class InputPane {
private Text server;
private Text textNumber;
private TextField tfNumber;
private Button addButton;
private GridPane griglia;
public InputPane() {
textNumber=new Text("Insert Port Number: ");
server = new Text("SERVER");
server.setStyle("-fx-font-weight:bold;"
+"-fx-color: black;"
+"-fx-font-size: 18;");
tfNumber = new TextField();
tfNumber.setTextFormatter(new TextFormatter<>(new NumberStringConverter()));
griglia=new GridPane();
griglia.add(server,1,0);
griglia.add(textNumber,0,1);
griglia.add(tfNumber,1,1);
griglia.setVgap(5);
griglia.setHgap(10);
GridPane.setHalignment(server, HPos.CENTER);
GridPane.setHalignment(textNumber, HPos.CENTER);
}
public GridPane getPane() {
return griglia;
}
public Button getAddButton() {
return addButton;
}
}
我给你一些想法,让你现在可以看到我的 GUI:
谢谢