我是Java新手。
我想在TextArea
中加入GridPane
。我在最近几个小时尝试了这个结果:
如您所见,TextArea
比Gridpane
大得多。这是我的代码:
GridPane root = new GridPane();
root.setGridLinesVisible(true);
root.setHgap(20);
root.setVgap(8);
root.setPadding(new Insets( 10, 10, 10, 10));
ColumnConstraints col1 = new ColumnConstraints();
col1.setPercentWidth(50);
ColumnConstraints col2 = new ColumnConstraints();
col2.setPercentWidth(50);
root.getColumnConstraints().addAll(col1,col2);
RowConstraints row1 = new RowConstraints();
RowConstraints row2 = new RowConstraints();
RowConstraints row3 = new RowConstraints();
RowConstraints row4 = new RowConstraints();
row1.setPrefHeight(20);
row2.setPrefHeight(20);
row3.setPrefHeight(40);
row4.setPrefHeight(20);
root.getRowConstraints().addAll(row1,row2,row3,row4);
GridPane.setVgrow(root, Priority.ALWAYS);
Label Opt1 = new Label("Operand 1");
Label Opt2 = new Label("Operand 2");
Label Erg = new Label("Ergebnis");
TextArea txtOpt1 = new TextArea();
TextArea txtOpt2 = new TextArea();
TextArea txtErg = new TextArea();
txtErg.setEditable(false);
Button btnPlus = new Button("+");
Button btnMinus = new Button("-");
Button btnMal = new Button("*");
Button btnGeteilt = new Button("/");
HBox Opts = new HBox(10);
HBox hblbl1 = new HBox();
hblbl1.getChildren().add(txtOpt1);
Opts.getChildren().add(btnGeteilt);
Opts.getChildren().add(btnMal);
Opts.getChildren().add(btnMinus);
Opts.getChildren().add(btnPlus);
Opts.setAlignment(Pos.CENTER);
root.add(Opt1, 0, 0);
root.add(Opt2, 0, 1);
root.add(hblbl1, 1, 0);
root.add(txtOpt2, 1, 1);
root.add(Opts, 0, 2, 2, 1);
root.add(Erg, 0, 3);
root.add(txtErg, 1, 3);