Any direction someone could point me in for auto-sizing only the last (right-most) column in a jtable? I want the user to be able to set the size of columns and be allowed to set them beyond the scrollable viewing area, but if the viewing area is wider than the column widths, then the last column would be auto-sized to fit the empty space.
Phaelax
52
Practically a Posting Shark
Recommended Answers
Jump to PostHave you tried setAutoResizeMode(int) using AUTO_RESIZE_LAST_COLUMN ?
Jump to PostNo, sorry, it won't. I should have checked it before suggesting.
Jump to PostTry this
Component c = evt.getComponent(); int viewWidth = c.getWidth(); int tableWidth = libraryTable.getWidth(); int diffWidth = viewWidth - tableWidth; if (diffWidth > 0) { TableColumn tc = libraryTable.getColumnModel().getColumn(libraryTable.getColumnCount()-1); tc.setPreferredWidth(tc.getWidth() + diffWidth - 3); }
The magic number 3 is just there to keep it from being …
All 10 Replies
Phaelax
52
Practically a Posting Shark
Phaelax
52
Practically a Posting Shark
Ezzaral
2,714
Posting Sage
Team Colleague
Featured Poster
Phaelax
52
Practically a Posting Shark
Ezzaral
2,714
Posting Sage
Team Colleague
Featured Poster
Ezzaral
2,714
Posting Sage
Team Colleague
Featured Poster
Phaelax
52
Practically a Posting Shark
Ezzaral
2,714
Posting Sage
Team Colleague
Featured Poster
Phaelax
52
Practically a Posting Shark
Phaelax
52
Practically a Posting Shark
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.