Expandable SplitPane : ScrollBar « Swing JFC « Java






Expandable SplitPane

Expandable SplitPane
  
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JSplitPane;

public class ExpandableSplit {
  public static void main(String args[]) {
    String title = (args.length == 0 ? "Expandable Split" : args[0]);

    JFrame vFrame = new JFrame(title);
    vFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComponent leftButton = new JButton("Top");
    JComponent rightButton = new JButton("Bottom");
    final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setOneTouchExpandable(true);
    splitPane.setLeftComponent(leftButton);
    splitPane.setRightComponent(rightButton);
    ActionListener oneActionListener = new ActionListener() {
      public void actionPerformed(ActionEvent event) {
        splitPane.resetToPreferredSizes();
      }
    };
    ((JButton) rightButton).addActionListener(oneActionListener);
    ActionListener anotherActionListener = new ActionListener() {
      public void actionPerformed(ActionEvent event) {
        splitPane.setDividerLocation(10);
        splitPane.setContinuousLayout(true);
      }
    };
    ((JButton) leftButton).addActionListener(anotherActionListener);
    vFrame.getContentPane().add(splitPane, BorderLayout.CENTER);
    vFrame.setSize(300, 150);
    vFrame.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.ScrollBar PiecesScrollBar Pieces
6.Listening for Scrollbar Value Changes in a JScrollPane Container
7.Get the default scrollbar policy
8.Make the scrollbars always appear
9.Make the scrollbars never appear
10.JScrollBar and Adjustment event
11.JScrollPane to hold scrollable component
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