A simple JScrollPane demonstration : Scrollpane « Swing JFC « Java






A simple JScrollPane demonstration

A simple JScrollPane demonstration
 
/*
Java Swing, 2nd Edition
By Marc Loy, Robert Eckstein, Dave Wood, James Elliott, Brian Cole
ISBN: 0-596-00408-7
Publisher: O'Reilly 
*/
// ScrollDemo.java
//A simple JScrollPane demonstration.
//

import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;

public class ScrollDemo extends JFrame {

  JScrollPane scrollpane;

  public ScrollDemo() {
    super("JScrollPane Demonstration");
    setSize(300, 200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    init();
    setVisible(true);
  }

  public void init() {
    JRadioButton form[][] = new JRadioButton[12][5];
    String counts[] = { "", "0-1", "2-5", "6-10", "11-100", "101+" };
    String categories[] = { "Household", "Office", "Extended Family",
        "Company (US)", "Company (World)", "Team", "Will",
        "Birthday Card List", "High School", "Country", "Continent",
        "Planet" };
    JPanel p = new JPanel();
    p.setSize(600, 400);
    p.setLayout(new GridLayout(13, 6, 10, 0));
    for (int row = 0; row < 13; row++) {
      ButtonGroup bg = new ButtonGroup();
      for (int col = 0; col < 6; col++) {
        if (row == 0) {
          p.add(new JLabel(counts[col]));
        } else {
          if (col == 0) {
            p.add(new JLabel(categories[row - 1]));
          } else {
            form[row - 1][col - 1] = new JRadioButton();
            bg.add(form[row - 1][col - 1]);
            p.add(form[row - 1][col - 1]);
          }
        }
      }
    }
    scrollpane = new JScrollPane(p);
    getContentPane().add(scrollpane, BorderLayout.CENTER);
  }

  public static void main(String args[]) {
    new ScrollDemo();
  }
}

           
         
  








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 Sample
6.Scrollpane rulerScrollpane ruler
7.Customized ScrollPaneCustomized ScrollPane
8.ScrollPane with imageScrollPane with image
9.Scrolling ProgrammaticallyScrolling Programmatically
10.A simple JScrollPane for a JList componentA simple JScrollPane for a JList component
11.JScrollPane with row and column headersJScrollPane with row and column headers
12.Watermark JScrollPane