Pin It

How to implement JScrollPane into a Frame in Java using Swing API ?.

A Simple program demonstrating the working of JScrollPane in Java using Swing framework.

package com.hubberspot.swing.example;

import javax.swing.*;
import java.awt.*;

public class ScrollPaneDemo extends JFrame {

  JScrollPane scrollpane;

  public ScrollPaneDemo() {

    String teams[] = { "Deccan Chargers", "Kolkata Night Riders", 
            "Mumbai Indians", "Chennai Super Kings", 
         "Rajasthan Royals", "Royal Challengers Bangalore",
         "Kings XI Punjab", "Pune Warriors India",
         "Delhi Daredevils"
  };

    JList list = new JList(teams);
    scrollpane = new JScrollPane(list);
    getContentPane().add(scrollpane, BorderLayout.CENTER);
  }

  public static void main(String[] args) {
    setFrame(new ScrollPaneDemo(), 300, 150);
  }

  public static void 
  setFrame(final JFrame frame, final int width, final int height) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        frame.setTitle(frame.getClass().getSimpleName());
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 frame.setSize(width, height);
 frame.setVisible(true);
      }
    });
  }

}


Output of the program : 


Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot