Java Swing How to - import java.awt.Container;








Question

We would like to know how to import java.awt.Container;.

Answer

import java.awt.GridLayout;
/*  w  w w . ja v a2 s . c  om*/
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class Main {
  public static void main(String[] args) {

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    JPanel panel = new JPanel();
    Container c = frame.getContentPane();
    panel.setSize(100, 100);
    panel.setLayout(new GridLayout(1000, 1));
    for (int i = 0; i < 1000; i++)
      panel.add(new JLabel("JLabel " + i));

    JScrollPane jsp = new JScrollPane(panel);
    c.add(jsp);
    frame.setSize(100, 100);
    frame.setVisible(true);

  }
}