Resize SplitPane : Splitpane « Swing JFC « Java






Resize SplitPane

Resize SplitPane
  

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

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

public class ResizeSplit {
  public static void main(String args[]) {
    String title = "Resize Split";

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

    JButton topButton = new JButton("Top");
    JButton bottomButton = new JButton("Bottom");
    final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(topButton);
    splitPane.setBottomComponent(bottomButton);
    ActionListener oneActionListener = new ActionListener() {
      public void actionPerformed(ActionEvent event) {
        splitPane.setResizeWeight(1.0);
        vFrame.setSize(300, 250);
        vFrame.validate();
      }
    };
    bottomButton.addActionListener(oneActionListener);

    ActionListener anotherActionListener = new ActionListener() {
      public void actionPerformed(ActionEvent event) {
        splitPane.setResizeWeight(0.5);
        vFrame.setSize(300, 250);
        vFrame.validate();
      }
    };
    topButton.addActionListener(anotherActionListener);
    vFrame.getContentPane().add(splitPane, BorderLayout.CENTER);
    vFrame.setSize(300, 150);
    vFrame.setVisible(true);

  }
}

           
         
    
  








Related examples in the same category

1.Create a left-right split pane
2.Create a top-bottom split pane
3.A quick test of the JSplitPane classA quick test of the JSplitPane class
4.SplitPane Demo 2
5.Swing SplitPane SampleSwing SplitPane Sample
6.SplitPane: VerticalSplitSplitPane: VerticalSplit
7.SplitPane Sample 3SplitPane Sample 3
8.Property SplitProperty Split
9.Use the split paneUse the split pane
10.Continuously move the divider and resize its child components while the user is dragging the divider
11.Getting the Setting the Children in a JSplitPane Container
12.Getting and Setting the Divider Location in a JSplitPane Container
13.Distributing Space When a JSplitPane Container Is Resized
14.The split pane supports a one-touch-expandable capability that allows the user to conveniently move the divider to either end with a single click
15.This program demonstrates the split pane component organizer.This program demonstrates the split pane component organizer.