ScrollSample.java Source code

Java tutorial

Introduction

Here is the source code for ScrollSample.java

Source

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);
    }
}