Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to make lowerRight component always visible inside JScrollPane.

843807Apr 17 2010 — edited Apr 19 2010
Hi.

I'm trying to modify JScrollPane to have right vertical scroll to have custom components on top of scroll and at the bottom.
I've modified ScrollPaneLayout class to achieve that. I did the following:
import java.awt.Container;
import java.awt.Rectangle;
import javax.swing.ScrollPaneLayout;

public class MyScrollPaneLayout extends ScrollPaneLayout {
  public void layoutContainer(Container parent) {
    super.layoutContainer(parent);
    Rectangle vsb_bounds = vsb.getBounds();
    vsb_bounds.y = vsb_bounds.y + 16;
    vsb_bounds.height = vsb_bounds.height - (16 * 4);
    vsb.setBounds(vsb_bounds);
    Rectangle upperRight_bounds = upperRight.getBounds();
    upperRight_bounds.height = upperRight_bounds.height + 16;
    upperRight.setBounds(upperRight_bounds);
    Rectangle lowerRight_bounds = lowerRight.getBounds();
    lowerRight_bounds.y = lowerRight_bounds.y - (16 * 3);
    lowerRight_bounds.height = lowerRight_bounds.height + (16 * 3);
    lowerRight.setBounds(lowerRight_bounds);
  }
}
and then in my main code:
scroll.setCorner(JScrollPane.UPPER_RIGHT_CORNER, component1);
scroll.setCorner(JScrollPane.LOWER_RIGHT_CORNER, component2);
MyScrollPaneLayout scroll_layout = new MyScrollPaneLayout();
scroll.setLayout(scroll_layout);
scroll_layout.syncWithScrollPane(scroll);
I have small problem with this code. component2 is ONLY visible when lower horizontal scroll bar is visible. I need both component1 and componet2 visible even when horizontal bar is not visible.

Can somebody help me with this?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 17 2010
Added on Apr 17 2010
13 comments
228 views