• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JScrollPane, JTable

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kate,
Did u try this.
table.setAutoCreateColumnsFromModel(false);
TableColumnModel colModel = table.getColumnModel();
colModel.getColumn(#).setPreferredWidth(##);


 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic