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
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

626 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