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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
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…
Suggested Courses

738 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