JScrollPane to hold scrollable component : ScrollBar « Swing JFC « Java






JScrollPane to hold scrollable component

 

import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.Box;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;

public class Main {
  public static void main(String args[]) {
    JFrame f = new JFrame();
    f.setLayout(new FlowLayout());
    f.setSize(240, 250);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JScrollPane jscrlpLabel = new JScrollPane(new JLabel(
        "<html>A<br>B<br>C<br>D<br>E<br>F<br>G<br>H<br></html>."));

    jscrlpLabel.setPreferredSize(new Dimension(200, 100));

    JLabel label = new JLabel("Option");
    JCheckBox a = new JCheckBox("A");
    JCheckBox b = new JCheckBox("B");
    JCheckBox c = new JCheckBox("C");
    JCheckBox d = new JCheckBox("D");
    JCheckBox e = new JCheckBox("E");

    Box box = Box.createVerticalBox();

    box.add(label);
    box.add(a);
    box.add(b);
    box.add(c);
    box.add(d);
    box.add(e);

    JScrollPane jscrlpBox = new JScrollPane(box);
    jscrlpBox.setPreferredSize(new Dimension(140, 90));
    f.add(jscrlpLabel);
    f.add(jscrlpBox);

    f.setVisible(true);
  }
}

   
  








Related examples in the same category

1.Accessible Scroll Demo Accessible Scroll Demo
2.A quick demonstration of JScrollBar both vertical and horizontalA quick demonstration of JScrollBar both vertical and horizontal
3.JScrollPane: Button Corner SampleJScrollPane: Button Corner Sample
4.JScrollPane CornerJScrollPane Corner
5.Expandable SplitPaneExpandable SplitPane
6.ScrollBar PiecesScrollBar Pieces
7.Listening for Scrollbar Value Changes in a JScrollPane Container
8.Get the default scrollbar policy
9.Make the scrollbars always appear
10.Make the scrollbars never appear
11.JScrollBar and Adjustment event
12.Use Adjustment Events in Swing
13.Always display scrollbar
14.How to use scrollbar and react to its actionHow to use scrollbar and react to its action