从javaFX中的用户二维数组获取的最佳方法 [英] The best way to get from user two dimensional array in javaFX

查看:158
本文介绍了从javaFX中的用户二维数组获取的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从用户那里获取矩阵。哪个JavaFX功能最有用?网格有(m * n)textFields还是TableView?问题是,很难用可变数量的列来表示TableView。

I need to get matrix from user. Which of the JavaFX features is the most useful? Grid with (m*n) textFields or TableView? The thing is, it is hard to represent TableView with variable number of columns.

推荐答案

我使用的是TextArea

I'd use a TextArea

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);
    }

}

我可能会做一些更好的格式化:)你可以也使用TextField但用括号或其他东西拆分。

I'd probably do some better formatting:) You could also use a TextField but split with brackets or something.

这篇关于从javaFX中的用户二维数组获取的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆