Friday 14 July 2017

ScrollPaneLayout in java ~ java help

The layout manager used by JScrollPane. JScrollPaneLayout is responsible for nine components: a viewport, two scrollbars, a row header, a column header, and four "corner" components.

Nested Class

Modifier and TypeClassDescription
static classScrollPaneLayout.UIResourceIt is UI resource version of ScrollPaneLayout.

Field

Modifier and TypeFieldDescription
protected JViewportcolHeadIt is column header child.
protected JScrollBarhsbIt is scrollpane's horizontal scrollbar child.
protected inthsbPolicyIt displays policy for the horizontal scrollbar.
protected ComponentlowerLeftThis displays the lower left corner.
protected ComponentlowerRightThis displays in the lower right corner.
protected JViewportrowHeadIt is row header child.
protected ComponentupperLeftThis component displays in the upper left corner.
protected ComponentupperRightThis component displays in the upper right corner.
protected JViewportviewportIt is scrollpane's viewport child.
protected JScrollBarvsbIt is scrollpane's vertical scrollbar child.
protected intvsbPolicyIt is the display policy for the vertical scrollbar.

Useful methods

Modifier and TypeMethodDescription
voidaddLayoutComponent(String s, Component c)It adds the specified component to the layout.
protected ComponentaddSingletonComponent(Component oldC, Component newC)It removes an existing component.
JViewportgetColumnHeader()It returns the JViewport object that is the column header.
ComponentgetCorner(String key)It returns the Component at the specified corner.
JScrollBargetHorizontalScrollBar()It returns the JScrollBar object that handles horizontal scrolling.
intgetHorizontalScrollBarPolicy()It returns the horizontal scrollbar-display policy.
JViewportgetRowHeader()It returns the JViewport object that is the row header.
JScrollBargetVerticalScrollBar()It returns the JScrollBar object that handles vertical scrolling.
intgetVerticalScrollBarPolicy()It returns the vertical scrollbar-display policy.
JViewportgetViewport()It returns the JViewport object that displays the scrollable contents.

Example:

  1. import javax.swing.ImageIcon;  
  2. import javax.swing.JFrame;  
  3. import javax.swing.JLabel;  
  4. import javax.swing.JScrollPane;  
  5. public class ScrollPaneDemo extends JFrame  
  6. {  
  7. public ScrollPaneDemo() {  
  8. super("ScrollPane Demo");  
  9. ImageIcon img = new ImageIcon("child.png");  
  10.   
  11. JScrollPane png = new JScrollPane(new JLabel(img));  
  12.   
  13. getContentPane().add(png);  
  14. setSize(300,250);  
  15. setVisible(true);  
  16. }  
  17.   
  18. public static void main(String[] args) {  
  19. new ScrollPaneDemo();  
  20. }  
  21. }  
Output:
Java Scrollpanellayout 1

No comments:

Post a Comment