简体   繁体   中英

prevent jtable column from resizing after certain value is exceeded

I have a jtable having a total column width of X pixels.

I want to prevent any column in that jtable from resizing when the total width exceeds that X pixels.

I tried PropertyChangeListener and other custom implementations in vain.

You need to set AUTO_RESIZE_OFF and you can manually handle the width for any column in JTable like:

table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.getColumnModel().getColumn(0).setPreferredWidth(123);
table.getColumnModel().getColumn(1).setPreferredWidth(250);
table.getColumnModel().getColumn(2).setPreferredWidth(123);
table.getColumnModel().getColumn(3).setPreferredWidth(125);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM