ScrollPane Sample : Scrollpane « Swing JFC « Java






ScrollPane Sample

 
import java.awt.BorderLayout;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;

public class ScrollSample {
  public static void main(String args[]) {
    String title = (args.length == 0 ? "JScrollPane Sample" : args[0]);
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Icon icon = new ImageIcon("dog.jpg");
    JLabel dogLabel = new JLabel(icon);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(dogLabel);
    //    scrollPane.getViewport().setView(dogLabel);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.setVisible(true);
  }
}

           
         
  








Related examples in the same category

1.Creating a JScrollPane Container
2.Create a scrollable list
3.Controlling the scrollbars in a JScrollPaneControlling the scrollbars in a JScrollPane
4.JViewport: Move and View JViewport: Move and View
5.Scrollpane rulerScrollpane ruler
6.Customized ScrollPaneCustomized ScrollPane
7.ScrollPane with imageScrollPane with image
8.Scrolling ProgrammaticallyScrolling Programmatically
9.A simple JScrollPane for a JList componentA simple JScrollPane for a JList component
10.JScrollPane with row and column headersJScrollPane with row and column headers
11.A simple JScrollPane demonstrationA simple JScrollPane demonstration
12.Watermark JScrollPane