0

I am trying to populate a jtable i have with data from a oracle table. I can successfully get the information from the table and into a list but how do i display this information in a jtable.

This is what i have

public class MainMenu extends javax.swing.JFrame {

    private DatabaseConnector dbConnector = new DatabaseConnector();

    DefaultTableModel userTableModel = new DefaultTableModel();

    public void refreshCustomersList() throws SQLException, ClassNotFoundException {

        UserBeanList userList = dbConnector.getUserData();

        userListModel.clear();

        for (int i = 0; i < userList.size(); i++) {
            UserBean userBean = userList.getUserBeanAt(i);

            String[] data = new String[3];

            data[0] = userBean.getCustomerID();
            data[1] = userBean.getFirstName();
            data[2] = userBean.getLastName();

            userTableModel.addRow(data);
        }
        tableCustomers.setModel(userTableModel);
    }

Am i doing something wrong cause why table is just all greyed out?

1 Answer 1

3

You forgot to specify the number of columns for your table model. I would suggest to use this constructor instead:

DefaultTableModel userTableModel = 
  new DefaultTableModel( new Object[]{ "Customer id", "First name", "Last name" }, 0 );
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.