Sara Khelifi
Sara Khelifi

Reputation: 27

Can't construct a JTable with int[][] and String[] arguments

The constructor JTable is giving me an error that says:

"The constructor JTable(int[][], String[]) is undefined"

although it has a constructor JTable(Object[][], Object[]) (Calcul.apartements is of the type int[][])

    String[] colonnes = {"Appartements", "Prix Milion de Cts", "Tempd duTrajet/C.v (en min)", "Superficie (en m2)", "Etage"};
    table  = new JTable(Calcul.appartements, colonnes);

Upvotes: 1

Views: 456

Answers (1)

AJNeufeld
AJNeufeld

Reputation: 8695

You have two choices:

  1. alter your Calcul.appartements data to be Object[][] or Integer[][] (as mentioned by @MadProgrammer in the comments)
  2. Implement your own table model.

Implementing the table model might be as simple as:

TableModel dataModel = new AbstractTableModel() {
        public int getColumnCount() { return colonnes.length; }
        public String getColumnName(int col) { return colonnes[col]; }
        public int getRowCount() { return Calcul.appartements.length; }
        public Object getValueAt(int row, int col) { Calcul.appartements[row][col]; }
    };
JTable table = new JTable(dataModel);

Upvotes: 1

Related Questions