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
312 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

744 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

13 Experts available now in Live!

Get 1:1 Help Now