Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
349 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

877 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