I have created a MigLayout, which looks like that:
As you can see the table does not resize correctly.
I am creating my layout like that:
public JScrollPane createLayout() {
JPanel panel = new JPanel(new MigLayout("debug 400"));
JScrollPane sp;
JLabel lab = new JLabel(labelValue);
lab.setFont(new Font("Tahoma", Font.BOLD, 15));
panel.add(lab, "wrap");
panel.add(resultsTable(), "growx, wrap");
panel.add(resultsButtons(), "wrap");
//set table properties
tableProperties(resultTable);
updateResultsTable();
sp = new JScrollPane(panel);
sp.repaint();
sp.validate();
return sp;
}
My table is created like that:
private JPanel resultsTable() {
JPanel panel = new JPanel(new MigLayout(""));
JScrollPane scrollTablePane;
rtm = new ResultTableModel(resultList);
resultTable = new JTable(rtm);
scrollTablePane = new JScrollPane(resultTable);
sorter = new TableRowSorter<TableModel>(resultTable.getModel());
resultTable.setRowSorter(sorter);
scrollTablePane.repaint();
scrollTablePane.validate();
//add to panel
panel.add(scrollTablePane);
panel.repaint();
panel.validate();
return panel;
}
Furthermore, I set the table properties in the following method:
public void tableProperties(JTable table) {
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
}
Any recommendations why my columns of my table do not stretch?
I appreciate your answer!
If you want your table to be auto resizable try to use inside
createLayout
method the following constructorJPanel panel = new JPanel(new MigLayout("debug 400,wrap 1","[grow,fill]","[grow,fill]"))
and insideresultsTable
method the following constructorJPanel panel = new JPanel(new MigLayout("","[grow,fill]","[grow,fill]"))