如果JTable小于面板大小,我想使用AUTO_RESIZE_ALL_COLUMNS
如果Jtable有更多列,那么我想使用滚动条将所有列保持在最大宽度
但是,当我尝试使用以下代码时,最后一栏会缩小。 我想知道我是否想念一些东西
//Adjust columns according to max width(header,Content)
TableColumnAdjuster tca = new TableColumnAdjuster(table);
tca.adjustColumns();
//Adjust the column to max width with double click if the column is shrinked
new ResizeColumnListner(table);
JScrollPane sp = new JScrollPane(table,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS , ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
table.getParent().addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(final ComponentEvent e) {
if (table.getPreferredSize().width < table.getParent().getWidth()) {
table.setAutoResizeMode(table.AUTO_RESIZE_ALL_COLUMNS);
} else {
table.setAutoResizeMode(table.AUTO_RESIZE_OFF);
}
}
});