GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Understanding Bounds for JTable and JScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Understanding Bounds for JTable and JScrollPane" Watch "Understanding Bounds for JTable and JScrollPane" New topic
Author

Understanding Bounds for JTable and JScrollPane

Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
I am having a problem getting my scrollable JTable set up correctly. My problem is the height of JScrollPane and/or JTable. The bottom part of the scroll bar is not visible within my JFrame. I have played with the height parameter of 'setBounds' for both the JTable and JScrollPane but neither seems to bring the bottom of the scroll bar into view. It seems like the bounds for the scroll pane should do it but I can't get it to effect anything. Can some educate me on what controls what? TIA.
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
Never mind. I got it and am too embarrassed to say what it was. Sorry.
Guillaume Jourdan
Ranch Hand

Joined: Jul 24, 2012
Posts: 47

Hello,

You must set AutoResizeMode at AUTO_RESIZE_OFF on your JTable.

If you don't do that, the JTable try to resize and ignore the scroll problem even if there is size problem.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4571
    
    5

Guillaume, what you suggest doesn't affect the stated problem:
The bottom part of the scroll bar is not visible within my JFrame.
I suspect the real issue was attempting absolute placement and sizing using the size of the JFrame instead of that of its contentPane. And if my suspicions are correct, then I have to say: don't use setBounds(...). Use an appropriate layout manager or a combination of them.


luck, db
There are no new questions, but there may be new answers.
Guillaume Jourdan
Ranch Hand

Joined: Jul 24, 2012
Posts: 47

I suggest you try and you give us the result.

Your bottom scrollbar is hide when your JTable is in auto-resize and your JTable is by default in auto-resize.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4571
    
    5

For the second time: the problem as stated isn't about the "bottom" -- or horizontal - scrollbar. Dennis clearly said that
The bottom part of the scroll bar is not visible within my JFrame.
Guillaume Jourdan
Ranch Hand

Joined: Jul 24, 2012
Posts: 47

Ok, we understand the sentence differently.

For me, I understand :
The bottom part of the scroll bar is not visible within my JFrame
is not only a piece of horizontal scrollbar. When auto-resize is off, right part of the scrollbar (vertical scrollbar) is visible but not bottom part.



How can I have a JTable in a JScrollPane with horizontal scroll bars?

table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
If autoResizeMode is set differently, the JTable automatically resizes itself to the width of the JScrollPane.

ref : http://www.chka.de/swing/table/faq.html



I have played with the height parameter of 'setBounds' for both the JTable and JScrollPane but neither seems to bring the bottom of the scroll bar into view.


@Dennis : It's possible that I have no understand the question, but for me, Darryl doesn't see the horizontal scrollbar.

@Darryl : Can you give us your code and a printscreen of your problem if I don't understand your problem ?
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
I'm kind of surprised that this thread is active since I said the problem was an embarrassing mistake on my part. However, if you two are going to have a debate then I will clarify by saying there is no horizontal scroll bar involved.
Guillaume Jourdan
Ranch Hand

Joined: Jul 24, 2012
Posts: 47

Ok, I have switch @Dennis and @Darryl ;p

Sorry Darryl, you've rigth, this is certainly a layout problem.

A simple setLayout(new BorderLayout(1,1)); on your frame may be suffisant for your case.
 
GeeCON Prague 2014
 
subject: Understanding Bounds for JTable and JScrollPane