Create JTable from ArrayList

前端 未结 2 1808
天涯浪人
天涯浪人 2021-01-27 09:40

Now that I managed to put the objects from a file into a ArrayList, I have to display them into a JTable.

These are the 3 objects contained in

2条回答
  •  花落未央
    2021-01-27 10:19

    Use your TableModel to create a JTable and add it to a JFrame. Also consider overriding getColumnName(), as shown here. See also How to Use Tables.

    MonModel model = new MonModel();
    JTable table = new JTable(model);
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new JScrollPane(table), BorderLayout.CENTER);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);
    

提交回复
热议问题