It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes how to increase the height of a JScrollpanes dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to increase the height of a JScrollpanes dynamically" Watch "how to increase the height of a JScrollpanes dynamically" New topic
Author

how to increase the height of a JScrollpanes dynamically

peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
there is a outer panel with border layout, then a panelUpper at BorderLayout.NORTH and a panelBottom at BorderLayout.BorderLayout.SOUTH and a JScrollPane scrForm at BorderLayout.CENTRE.
the scrForm contain a panel pnlForm
scrForm.getViewport().add(pnlForm)
and at runtime, the pnlForm will add a panel panelPAMM
pnlForm.add(pnlPAMM)
so the pnlForm will increase its height at runtime,
now the problem is when the pnlForm incrrease its height, the outer JScrollpane scrForm shows a vertical scrollbar to let user scroll down to the increased area, but I want the scrForm to increase its height to accomodate the pnlForm instead of showing the vertical scrollbar, only when the JScrollpane scrForm increase to a maximum height then it show the vertical scrollbar instead, how to implement it?
peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
I have try to increase the JViewport.viewsize by
scrForm.getViewport().setViewSize(new Dimension(400, 800));
but it does not help, the scrForm height has not been increased.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
your description makes little sense.

scrForm at BorderLayout.CENTER will occupy all the available space
leftover in the frame after allocating the other BorderLayout positions.

so, do you mean that when pnlForm increases its height you want the
actual JFrame to also increase its height (which will increase scrForm's height),
until scrForm's max height has been reached, then the scrollbars appear?

if so, that would look really weird
peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
Michael Dunn wrote:your description makes little sense.

scrForm at BorderLayout.CENTER will occupy all the available space
leftover in the frame after allocating the other BorderLayout positions.

so, do you mean that when pnlForm increases its height you want the
actual JFrame to also increase its height (which will increase scrForm's height),
until scrForm's max height has been reached, then the scrollbars appear?

if so, that would look really weird


yes, this is what I want to archieve, is there any way to implement it?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

You can call pack() on the JFrame again, or its setSize() method.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
jQuery in Action, 2nd edition
 
subject: how to increase the height of a JScrollpanes dynamically
 
Similar Threads
Very Different Problem with JScrollPane
Problem with Layouts
The scrollbar is unable for uneditable JTextArea?
Jtree Scrolling problem
JScrollBar problem???