Forums Register Login

JScrollPane, JTable

+Pie Number of slices to send: Send
Hi,
I have several JTables in JScrollPanes. Most have 6 or so columns of data and look great. One has thirty columns. I have the scrollpanes set to HORIZONTAL_SCROLLPANE_ALWAYS.
The table with lots of columns displays all, very small. I want to set the sizes so that most of them are not in the displayed area, the user should scroll to reach them. So far, all attempts at setting the width of a column have been unsuccessful.
Also, I suspect that the horizontal scroll bar isn't working anyway. THe vertical one is fine - it has a purple slider on it and I can scoll. However, even if I resize the columns manually to really wide, so that some columns would have to disappear out of view, I get no purple slider on the horizontal bar. Instead, the columns simply seem to disappear.
any ideas ?
Thanks,
Kate
+Pie Number of slices to send: Send
You need the get the TableColumn like this column = table.getColumnModel().getColumn(i). Then you can set the width column.setPreferredWidth(##). You can also set minimum width.
+Pie Number of slices to send: Send
Hi Paul,
thanks for that. setMinWidth does have the desired effect, that I can make the first few columns wide enough for their data. However, the scrollbar steadfastly refuses to scroll, so I'm just losing colmns now.
Kate
+Pie Number of slices to send: Send
Hi Kate,
Did u try this.
table.setAutoCreateColumnsFromModel(false);
TableColumnModel colModel = table.getColumnModel();
colModel.getColumn(#).setPreferredWidth(##);


+Pie Number of slices to send: Send
Hai Kate,
I guess you should be successfull in setting the preferred column widths in JTable, yet you will not be seeing the scroll pane, since if we scroll some of the columns, the adjacent columns gets adjusted and fits within the viewport area, hence to have the HORIZONTAL SCROLL BAR always, set the minimum width for all the columns and set the setAutoResizeMode(0), you will get the scroll bar, especially for the table with more no. of columns.
table.setAutoResizeMode(0);
column = table.getColumnModel().getColumn(columnIndex);
column.setMinWidth(80);
after setting this, as usual you add the table to the scroll pane, you will get the horizontal sliding successfully.
if possible, let me know your result..
Have a great day.
-sakthi.
+Pie Number of slices to send: Send
Hi Sakti, Rajan, Paul,..
thankyou for your help ... my tables look lovely now - that line about setAutoResizeMode(0); gave me back my scroller.
Fantastic !
Kate
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1794 times.
Similar Threads
JTable and Horizontal Scroll Bar
Horizontal Scroll Bar
relayouting after setViewportView for JScrollPane
Apache POI - XSSFWorkbook - Disable Horizontal Scroll Bar
Horizontal scroll bar for SPECIFIC columns
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:46:14.