1

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);
2
  • 1
    int is not an Object. Either trying defining the array as Object[][] and put ints into it or use Integer[][] instead Commented Nov 28, 2017 at 21:19
  • @AJNeufeld What I intended to say and what my fingers said seem to be at odds far to often :P Commented Nov 28, 2017 at 21:23

1 Answer 1

1

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