-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.1
-
generic
-
generic
The ScrollPane documentation states:
[ o ] setScrollPosition
public void setScrollPosition(int x,
int y)
Scrolls to the specified position within the child component. A call to
this method is only valid if the scroll pane contains a child and the
specified position is within legal scrolling bounds of the child. Legal
bounds are defined to be the rectangle: x = 0, y = 0, width = (child
width - view port width), height = (child height - view port height).
This is a convenience method which interfaces with the Adjustable
objects which respresent the state of the scrollbars.
Parameters:
x - the x position to scroll to
y - the y position to scroll to
Throws: IllegalArgumentException
if specified coordinates are not within the legal scrolling bounds
of the child component.
If the coordinates supplied to setScrollPosition() are not within the
legal scrolling bounds of the child component, an IllegalArgumentException
is not thrown as documented.
The scroll position is actually set to the closest valid position.
The application below demonstrates this.
/*
ScrollpaneAlways2.java
This application displays a scrollpane with scrollbar display
policy SCROLLBARS_ALWAYS
*/
import java.awt.*;
import java.awt.event.*;
public class ScrollpaneAlways2 extends Frame {
public ScrollpaneAlways2 () {
setLayout(new BorderLayout());
setFont(new Font("Helvetica", Font.PLAIN, 14));
}
public static void main(String args[]) {
ScrollpaneAlways2 window = new ScrollpaneAlways2();
// Panel for the scrollpane
Panel scrollpanePanel = new Panel();
// Scrollpane
ScrollPane scrollpane_always = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
// Child of scrollpane
Panel panel_always = new Panel();
// Scrollbar states
Adjustable spVadj_always = scrollpane_always.getHAdjustable();
Adjustable spHadj_always = scrollpane_always.getVAdjustable();
// Child of scrollpane
panel_always.setBackground(Color.green);
// Set size of scrollpane
scrollpane_always.setSize(150, 300);
// Add child to scrollpane
scrollpane_always.add(panel_always);
// Add scrollpane to scrollpane panel
scrollpanePanel.setLayout(new GridLayout(0, 1));
scrollpanePanel.add(scrollpane_always);
// Add scrollpane panel to window
window.add("North", scrollpanePanel);
// Display window
window.setTitle("ScrollpaneAlways2 Application");
window.addWindowListener(new EventAdapter());
window.pack();
window.show();
// Make child bigger than scrollpane
scrollpane_always.getComponent(0).setSize(500, 500);
System.out.println("Child size: " + scrollpane_always.getComponent(0).getSize());
System.out.println("Viewport size: " + scrollpane_always.getViewportSize());
System.out.println("Current scroll position is " + scrollpane_always.getScrollPosition());
scrollpane_always.setScrollPosition(100,100);
System.out.println(" After scrollpane_always.setScrollPosition(100,100), ");
System.out.println(" new scroll position is " + scrollpane_always.getScrollPosition());
scrollpane_always.setScrollPosition(-1000000,-1000000);
System.out.println(" After scrollpane_always.setScrollPosition(-100000,-100000), ");
System.out.println(" new scroll position is " + scrollpane_always.getScrollPosition());
scrollpane_always.setScrollPosition(1000000,1000000);
System.out.println(" After scrollpane_always.setScrollPosition(100000,100000), ");
System.out.println(" new scroll position is " + scrollpane_always.getScrollPosition());
}
}
// ******************************* EventAdapter ***************************
class EventAdapter implements WindowListener {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowOpened(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
}
[ o ] setScrollPosition
public void setScrollPosition(int x,
int y)
Scrolls to the specified position within the child component. A call to
this method is only valid if the scroll pane contains a child and the
specified position is within legal scrolling bounds of the child. Legal
bounds are defined to be the rectangle: x = 0, y = 0, width = (child
width - view port width), height = (child height - view port height).
This is a convenience method which interfaces with the Adjustable
objects which respresent the state of the scrollbars.
Parameters:
x - the x position to scroll to
y - the y position to scroll to
Throws: IllegalArgumentException
if specified coordinates are not within the legal scrolling bounds
of the child component.
If the coordinates supplied to setScrollPosition() are not within the
legal scrolling bounds of the child component, an IllegalArgumentException
is not thrown as documented.
The scroll position is actually set to the closest valid position.
The application below demonstrates this.
/*
ScrollpaneAlways2.java
This application displays a scrollpane with scrollbar display
policy SCROLLBARS_ALWAYS
*/
import java.awt.*;
import java.awt.event.*;
public class ScrollpaneAlways2 extends Frame {
public ScrollpaneAlways2 () {
setLayout(new BorderLayout());
setFont(new Font("Helvetica", Font.PLAIN, 14));
}
public static void main(String args[]) {
ScrollpaneAlways2 window = new ScrollpaneAlways2();
// Panel for the scrollpane
Panel scrollpanePanel = new Panel();
// Scrollpane
ScrollPane scrollpane_always = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
// Child of scrollpane
Panel panel_always = new Panel();
// Scrollbar states
Adjustable spVadj_always = scrollpane_always.getHAdjustable();
Adjustable spHadj_always = scrollpane_always.getVAdjustable();
// Child of scrollpane
panel_always.setBackground(Color.green);
// Set size of scrollpane
scrollpane_always.setSize(150, 300);
// Add child to scrollpane
scrollpane_always.add(panel_always);
// Add scrollpane to scrollpane panel
scrollpanePanel.setLayout(new GridLayout(0, 1));
scrollpanePanel.add(scrollpane_always);
// Add scrollpane panel to window
window.add("North", scrollpanePanel);
// Display window
window.setTitle("ScrollpaneAlways2 Application");
window.addWindowListener(new EventAdapter());
window.pack();
window.show();
// Make child bigger than scrollpane
scrollpane_always.getComponent(0).setSize(500, 500);
System.out.println("Child size: " + scrollpane_always.getComponent(0).getSize());
System.out.println("Viewport size: " + scrollpane_always.getViewportSize());
System.out.println("Current scroll position is " + scrollpane_always.getScrollPosition());
scrollpane_always.setScrollPosition(100,100);
System.out.println(" After scrollpane_always.setScrollPosition(100,100), ");
System.out.println(" new scroll position is " + scrollpane_always.getScrollPosition());
scrollpane_always.setScrollPosition(-1000000,-1000000);
System.out.println(" After scrollpane_always.setScrollPosition(-100000,-100000), ");
System.out.println(" new scroll position is " + scrollpane_always.getScrollPosition());
scrollpane_always.setScrollPosition(1000000,1000000);
System.out.println(" After scrollpane_always.setScrollPosition(100000,100000), ");
System.out.println(" new scroll position is " + scrollpane_always.getScrollPosition());
}
}
// ******************************* EventAdapter ***************************
class EventAdapter implements WindowListener {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowOpened(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
}