1

I have a student object with the following attributes:

private String forename;
private String surname;
private String id;
private char gender;
private String street;
private String locality;
private String postcode;
private String email;

I have several of these objects stored in an ArrayList and wanted to know the best way to get them into a JTable with columns named after the attributes above.

2

1 Answer 1

3

You can use do it simply like this. or check this answer as well.Load arrayList data into JTable

  public void populateReadersTable(ReaderList readerList) {
        DefaultTableModel model = (DefaultTableModel) jTableReaders.getModel();
        model.setRowCount(0);
        model.setColumnCount(0);
        model.addColumn("ID");
        model.addColumn("First Name");
        model.addColumn("Last Name");
        model.addColumn("Email");
        model.addColumn("Mobile");
        model.addColumn("Street");
        model.addColumn("City");
        model.addColumn("Postal Code");
        model.addColumn("National ID");

        for (Reader reader : readerList) {
            model.addRow(reader.toStringArray());
        }

    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.