问题
I have a more simpler program that just shows the name and the address. I am playing around with place in the gridpane to put these things. Eventually, I would like a combobox, and a clockAnimation in the gridpane. I really don't know how to use HBox/VBox within gridpane, and if I can use them and label and text together. What I am trying to do is put a combo box in the middle of the gridpane, and a clock on the right. I would like to use the the gridpane, and HBox and VBox. I just don't want to use Borderpane, but Gridpane. I have a simple combo box, but it gets put into the wrong places when I am using Gridpane for the first time.
Here is the program:
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
//import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.control.Alert;
public class GridPane_Test extends Application {
public enum choices { // USE PRIVATE circle, rectangle, triangle??
CHOOSE_ONE, CIRCLE, RECTANGLE, TRIANGLE
}
protected GridPane getGPane() {
//Label lblName = new Label("Enter the name:\t");
/*
txtName = new TextField();
txtName.setMinWidth(100);
txtName.setPrefWidth(200);
txtName.setMaxWidth(1700);
txtName.setPromptText("Enter the name here:\t");
*/
//VBox paneSize = new VBox()
GridPane gPane = new GridPane();
gPane.setPadding(new Insets(10));
gPane.setHgap(10);
gPane.setVgap(10);
gPane.setMinWidth(500);
gPane.setMaxWidth(800);
gPane.setPrefWidth(500);
TextField txtName;
Label lblName = new Label("Enter the name:\t");
txtName = new TextField();
txtName.setMinWidth(100);
txtName.setPrefWidth(200);
txtName.setMaxWidth(1700);
txtName.setPromptText("Enter the name here:\t");
TextField txtAddress;
//Create address for label and text
Label lblAddress = new Label("Enter the Address:\t");
txtAddress = new TextField();
//lblAddress.maxHeight(1200);
//lblAddress.maxWidth(1200);
txtAddress.setMinWidth(100);
txtAddress.setPrefWidth(200);
txtAddress.setMaxWidth(300);
txtAddress.setPromptText("Enter the address here:\t");
//VBox paneSize = new VBox(lblSize, rdoSmall, rdoMedium, rdoLarge);
HBox testN_A = new HBox(lblName, txtName, lblAddress, txtAddress);
gPane.add(lblName, 10, 5);
gPane.add(txtName, 11, 5);
gPane.add(lblAddress, 10, 6);
gPane.add(txtAddress, 11, 6);
gPane.addRow(2, testN_A); //????
//gPane.addColumn(15, lblName, txtName);
return gPane;
}
@Override
public void start(Stage primaryStage) {
Scene scene = new Scene(getGPane(), 900, 700);
primaryStage.setTitle("Hello GridPane!!!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I included the old gridpane program. I know it is old an I need to work on the Message part. I have a combo box that does this, but I need to understand the gridpane.
Thanks
My messagebox does not work in this GridPane
来源:https://stackoverflow.com/questions/59692791/i-am-trying-to-understand-gridpane-and-how-to-use-it-with-combobox-and-vbox-hbo