File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JScrollPane, JTable

 
kate damond
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Stevens
Ranch Hand
Posts: 2823
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
kate damond
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Javaoops
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kate,
Did u try this.
table.setAutoCreateColumnsFromModel(false);
TableColumnModel colModel = table.getColumnModel();
colModel.getColumn(#).setPreferredWidth(##);


 
cs sakthi
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
kate damond
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic