0

I have some troubles with adding JScrollPane to JTable in my application. There are two classes: Controller and Main form.

In Main form the table is initialized as private variable, and in Controller I'm getting it using getter. Now I have such code in Controller to create and update table using TableModel:

private void updateTables(String[][] distanceMatrixData, String[] columnNames) {
    TableModel distanceMatrixModel = new DefaultTableModel(distanceMatrixData, columnNames);
    mainForm.getDistanceMatrix().setModel(distanceMatrixModel);
}

I don't have idea how to implement JScrollPane to this code because I don't create the table object.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Bersh
  • 1
  • 2
    When you create the JTable you add the table to the JScrollPane and add the scroll pane to the frame. Then when you update the model of the table the scrollbars will appear when required. See: https://stackoverflow.com/questions/1539329/sorting-jtable-programmatically/1539602#1539602 for a simple example. – camickr May 20 '21 at 18:37
  • 1
    *"I don't create the table object"* Are you using a drag'n'drop GUI designer? That doesn't bode well. Most people here won't help you figure out problems with your IDE. It's better to learn how to write the code yourself. Then you have complete control over components involved. – Andrew Thompson May 20 '21 at 18:49

0 Answers0