-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.1
-
generic
-
generic
The ScrollPane documentation states:
If the scrollbar display policy is defined as "never", then the scrollpane
can still be programmatically scrolled using the setScrollPosition() method
and the scrollpane will move and clip the child's contents appropriately.
The application below brings up a scrollpane with the scrollbar display
policy SCROLLBARS_NEVER, and attempts to scroll it using setScrollPosition().
getScrollPosition() continues to return (0,0) after setScrollPosition() is
invoked.
/*
ScrollpaneNever2.java
This application displays a scrollpane with scrollbar display
policy SCROLLBARS_NEVER
*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class ScrollpaneNever2 extends Frame {
public ScrollpaneNever2 () {
setLayout(new BorderLayout());
setFont(new Font("Helvetica", Font.PLAIN, 14));
}
public static void main(String args[]) {
ScrollpaneNever2 window = new ScrollpaneNever2();
// Panel for the scrollpane
Panel scrollpanePanel = new Panel();
// Scrollpane
ScrollPane scrollpane_never = new ScrollPane(ScrollPane.SCROLLBARS_NEVER);
//ScrollPane scrollpane_never = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
// Child of scrollpane
Panel panel_never = new Panel();
// Scrollbar states
Adjustable spVadj_never = scrollpane_never.getHAdjustable();
Adjustable spHadj_never = scrollpane_never.getVAdjustable();
// Child of scrollpane
//panel_never.setSize(150, 300);
panel_never.setBackground(Color.red);
// Set size of scrollpane
scrollpane_never.setSize(150, 300);
// Add child to scrollpane
scrollpane_never.add(panel_never);
// Add scrollpane to scrollpane panel
scrollpanePanel.setLayout(new GridLayout(0, 1));
scrollpanePanel.add(scrollpane_never);
// Add scrollpane panel to window
window.add("North", scrollpanePanel);
// Display window
window.setTitle("ScrollpaneNever2 Application");
window.addWindowListener(new EventAdapter());
window.pack();
window.show();
// Make child bigger than scrollpane
scrollpane_never.getComponent(0).setSize(500, 500);
System.out.println("Child size: " + scrollpane_never.getComponent(0).getSize());
System.out.println("Viewport size: " + scrollpane_never.getViewportSize());
System.out.println("Current scroll position is " + scrollpane_never.getScrollPosition());
scrollpane_never.setScrollPosition(100,100);
System.out.println(" After scrollpane_never.setScrollPosition(100,100), ");
System.out.println(" new scroll position is " + scrollpane_never.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) {}
}
If the scrollbar display policy is defined as "never", then the scrollpane
can still be programmatically scrolled using the setScrollPosition() method
and the scrollpane will move and clip the child's contents appropriately.
The application below brings up a scrollpane with the scrollbar display
policy SCROLLBARS_NEVER, and attempts to scroll it using setScrollPosition().
getScrollPosition() continues to return (0,0) after setScrollPosition() is
invoked.
/*
ScrollpaneNever2.java
This application displays a scrollpane with scrollbar display
policy SCROLLBARS_NEVER
*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class ScrollpaneNever2 extends Frame {
public ScrollpaneNever2 () {
setLayout(new BorderLayout());
setFont(new Font("Helvetica", Font.PLAIN, 14));
}
public static void main(String args[]) {
ScrollpaneNever2 window = new ScrollpaneNever2();
// Panel for the scrollpane
Panel scrollpanePanel = new Panel();
// Scrollpane
ScrollPane scrollpane_never = new ScrollPane(ScrollPane.SCROLLBARS_NEVER);
//ScrollPane scrollpane_never = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
// Child of scrollpane
Panel panel_never = new Panel();
// Scrollbar states
Adjustable spVadj_never = scrollpane_never.getHAdjustable();
Adjustable spHadj_never = scrollpane_never.getVAdjustable();
// Child of scrollpane
//panel_never.setSize(150, 300);
panel_never.setBackground(Color.red);
// Set size of scrollpane
scrollpane_never.setSize(150, 300);
// Add child to scrollpane
scrollpane_never.add(panel_never);
// Add scrollpane to scrollpane panel
scrollpanePanel.setLayout(new GridLayout(0, 1));
scrollpanePanel.add(scrollpane_never);
// Add scrollpane panel to window
window.add("North", scrollpanePanel);
// Display window
window.setTitle("ScrollpaneNever2 Application");
window.addWindowListener(new EventAdapter());
window.pack();
window.show();
// Make child bigger than scrollpane
scrollpane_never.getComponent(0).setSize(500, 500);
System.out.println("Child size: " + scrollpane_never.getComponent(0).getSize());
System.out.println("Viewport size: " + scrollpane_never.getViewportSize());
System.out.println("Current scroll position is " + scrollpane_never.getScrollPosition());
scrollpane_never.setScrollPosition(100,100);
System.out.println(" After scrollpane_never.setScrollPosition(100,100), ");
System.out.println(" new scroll position is " + scrollpane_never.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) {}
}