I Iは、行数が同じでdynimically 2 GridPanesを作成していた中でのJavaFXでアプリケーションを作成しています、両方GridPanesは、テキストフィールドを持っており、以下、このようなボタンがあります:JavaFX:ダイナミックに作成されたTextFieldの値から平均を計算する方法は?
ユーザーが書き込むことができますこのようなGridPane Aの動的に作成テキストフィールド内の任意の数:ユーザーがボタンのプログラムが各行に存在する値の合計を計算し、各ROを分割すべき送信]を押しますとき
私が欲しいものです全体GridPaneのテキストフィールドの和で計算和wおよび第二GridPaneのテキストフィールドに結果を表示GridPane行位置に応じて、例えばGridPane行0の計算結果は次のようGridPane B行0に表示されるべきである:
I」はM本GridPane AようGridPane作成:
public static GridPane tableA(int rows, Button button){
GridPane table = new GridPane();
rowValidationBindings = new BooleanBinding[rows];
for(int i=0; i<rows; i++){
TextField textField1 = new TextField();
textField1.setAlignment(Pos.CENTER);
TextField textField2 = new TextField();
textField2.setAlignment(Pos.CENTER);
TextField textField3 = new TextField();
textField3.setAlignment(Pos.CENTER);
rowValidationBindings[i] = Bindings.createBooleanBinding(
() -> {
if (textField1.getText().matches("\\d+") &&
textField2.getText().matches("\\d+") &&
textField1.getText().matches("\\d+") {
return true ;
} else {
return false ;
}
}, textField1.textProperty(), textField2.textProperty(), textField3.textProperty()
);
table.add(textField1, 0, i+1);
table.add(textField2, 1, i+1);
table.add(textField3, 2, i+1);
}
button.disableProperty().bind(Bindings.createBooleanBinding(
() -> ! Stream.of(rowValidationBindings).allMatch(BooleanBinding::get),
rowValidationBindings
));
return table;
}
GridPane B
public static GridPane tableB(int rows, Button button){
GridPane table = new GridPane();
rowValidationBindings = new BooleanBinding[rows];
for(int i=0; i<rows; i++){
TextField textField1 = new TextField();
textField1.setAlignment(Pos.CENTER);
rowValidationBindings[i] = Bindings.createBooleanBinding(
() -> {
if (textField1.getText().matches("\\d+") {
return true ;
} else {
return false ;
}
}, textField1.textProperty()
);
table.add(textField1, 0, i+1);
}
button.disableProperty().bind(Bindings.createBooleanBinding(
() -> ! Stream.of(rowValidationBindings).allMatch(BooleanBinding::get),
rowValidationBindings
));
return table;
}
法T O特定の行と列のテーブルからコンポーネントを返します。
public static Node getComponent (int row, int column, GridPane table) {
for (Node component : table.getChildren()) { // loop through every node in the table
if(GridPane.getRowIndex(component) == row &&
GridPane.getColumnIndex(component) == column) {
return component;
}
}
return null;
}
ボタンの実装をクリックしてください:私はあなたのアプローチはそれを達成するための正しい方法であると思い
@FXML
private void calcul() {
GridPane table = (GridPane) anchorPane.getChildren().get(0);
for(int i=1 ; i<=comboxBox.getValue(); i++){
String text0 = ((TextField) getComponent (i, 0, table)).getText();
String text1 = ((TextField) getComponent (i, 1, table)).getText();
String text2 = ((TextField) getComponent (i, 2, table)).getText();
System.out.println(text0 + " " + text1 + " " + text2);
System.out.println("Next Row");
}
私たちは何が必要明確であるが、私はあなたが問題が何であるか教えてくれたとは思わない... – Jai
私はこれが数日前に答えられたと確信しています。 – Sedrick
@SedrickJefferson既に回答済みの場合は、ここで既に回答している質問にタグを付けることができますか? – Junaid