Solved

Need to get a Horizontal Scroll Bar in my JTable that uses a JScroll Pane and avoid my columns from getting too narrow to display many columns of data

Posted on 2006-11-12
5
318 Views
Last Modified: 2012-06-27
I have a JTable that uses a JScroll Pane in a Java Swing GUI.  I will have lots of columns of data.  I want my JTable to get wider and my column widths to NOT get narrow and get a horizontal scroll bar when this happens.  Will this happen automatically or do I need to add some code to make it happen?

Thanks,
Dave
0
Comment
Question by:gdkinney_2
  • 2
  • 2
5 Comments
 

Author Comment

by:gdkinney_2
ID: 17926228
My JTable uses the AbstractTableModel class so my columns are resizeable by the user.
0
 
LVL 26

Accepted Solution

by:
ksivananth earned 500 total points
ID: 17928038
try,

yourtable.setAutoResizeMode( JTable.AUTO_RESIZE_OFF ) ;
0
 

Author Comment

by:gdkinney_2
ID: 17935789
Hi ksivananth,
    I tried that, right now I only have six columns in my table later I will have more.  When I use it with fewer columns like now, my JTable does not span the width of it's parent container which I want it to do.
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 17936242
can you post the code?
0
 
LVL 2

Expert Comment

by:saintsairforce
ID: 17953823
WHat you can do is have the dimension of the window sent to your method. And then take the number of columns you do have and devide the width by that number. So lets say your view window is 300 pixels wide and you have 6 columns. You then want to set the width of your columns to 300/6 pixels wide. You can then add in an if statement that will avoid this process if the standard width times the number of columns is greater than your window width.

Hope this helps.

Cheers,
Ricky
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
base64 decode encode 12 122
Free Alternative to JIRA 4 91
sites similar to codingbat to improve coding hanson skills 3 41
stackato and cloud 4 74
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now