User interface javaFX中从用户二维数组获取数据的最佳方法
我需要从用户那里得到矩阵。JavaFX的哪些特性最有用?使用(m*n)文本字段或表格视图的网格?问题是,很难用可变列数表示TableView。我会使用TextAreaUser interface javaFX中从用户二维数组获取数据的最佳方法,user-interface,matrix,javafx,User Interface,Matrix,Javafx,我需要从用户那里得到矩阵。JavaFX的哪些特性最有用?使用(m*n)文本字段或表格视图的网格?问题是,很难用可变列数表示TableView。我会使用TextArea public class Matrix extends Application { @Override public void start(Stage primaryStage) { TextArea txt = new TextArea(); GridPane grid = n
public class Matrix extends Application {
@Override
public void start(Stage primaryStage) {
TextArea txt = new TextArea();
GridPane grid = new GridPane();
grid.setGridLinesVisible(true);
txt.setOnKeyReleased(t-> {
int i = 0;
String[] rows = txt.getText().split("\n");
for (String row: rows){
String[] cols = row.split("\\s+");
int j = 0;
for (String col : cols)
grid.add(new Text(col), j++, i);
i++;
}
});
VBox root = new VBox(txt, grid);
Scene scene = new Scene(root, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
我可能会做一些更好的格式化:)你也可以使用文本字段,但要用括号或其他什么分开。你的问题需要更具体一些。阵列有多大?数组及其UI表示将用于什么?数组大小是固定的还是可变的?您是否已尝试解决此问题?如果是,您在尝试解决此问题时遇到了哪些问题?你的问题中有没有你尝试的解决方案的代码?数组大小是可变的,最大为7*7,我没有解决这个问题的想法。这很有趣。谢谢。