aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Implementing the Scrollable interface: viewport size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Implementing the Scrollable interface: viewport size" Watch "Implementing the Scrollable interface: viewport size" New topic
Author

Implementing the Scrollable interface: viewport size

Henry Leung
Greenhorn

Joined: Oct 26, 2003
Posts: 24
I have written a JScrollablePanel that extends JPanel and implements the Scrollable interface. There is one method that troubles me alot: getPreferredScrollableViewportSize(). I don't want to hardcode a size to be returned. I want the viewport's size to be dynamic, that means, depends on the area the JScrollPane(the component that contains the JScrollablePanel) is allocated during runtime. i.e. If I resize the JFrame (the out-most container that holds all the swing components of my GUI program) at runtime, the viewport should resize itself too. So I tried to return the sizes below, but none of them works in the way I want:
return this.getSize();
return this.getPreferredSize();
return this.getParent().getSize();
return this.getParent().getPreferredSize();
what should I actually return in this method?
Fuqiang Zhao
Greenhorn

Joined: Jan 07, 2004
Posts: 24
The problem is not in this method:
getPreferredScrollableViewportSize()

you should look the JScrollablePanel class or use the following method:
public boolean getScrollableTracksViewportWidth() {
return true;
}
public boolean getScrollableTracksViewportHeight() {
return true;
}
Henry Leung
Greenhorn

Joined: Oct 26, 2003
Posts: 24
I read the JavaDoc. These 2 methods only tell whether my JScrollablePanel's size should or should not depends on the viewport's size. That means, if I return true in these 2 methods, my JScrollablePanel's size will become dynamic and resize itself whenever the viewport that display it is resized. But the viewport's size is still not dynamic.....
Am I right?
Fuqiang Zhao
Greenhorn

Joined: Jan 07, 2004
Posts: 24
It seems that the JScrollPane is not dynamic in your program.
What's the layout manager that your JScrollPane parent container use?
Can you post some code?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Implementing the Scrollable interface: viewport size