gdkinney_2
asked on
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
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
Thanks,
Dave
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
can you post the code?
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
Hope this helps.
Cheers,
Ricky
ASKER