FileDocCategorySizeDatePackage
SplitPanePanel.javaAPI DocExample10207Sat Sep 12 03:01:00 BST 1998None

SplitPanePanel

public class SplitPanePanel extends JPanel

Fields Summary
protected JSplitPane
splitPane
JSplitPane being shown to the user.
protected GridComponent
leftGrid
Left component being split.
protected GridComponent
rightGrid
Right component being split.
protected SwingSet
swing
Grand puba swingset.
Constructors Summary
public SplitPanePanel(SwingSet swing)

	super();
	this.swing = swing;
	setDoubleBuffered(true);
	setLayout(new BorderLayout());
	createSplitPane();
	createInformationControls();
    
Methods Summary
protected voidcreateInformationControls()
Creates controls to alter the JSplitPane.

	JPanel                wrapper = new JPanel();
	ButtonGroup           group = new ButtonGroup();
	JRadioButton          button;

	Box                   buttonWrapper = new Box(BoxLayout.X_AXIS);

	wrapper.setLayout(new GridLayout(0, 1));

	/* Create a radio button to vertically split the split pane. */
	button = new JRadioButton("Vertically split");
	button.setMnemonic('V");
	button.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent e) {
		splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
	    }
	});
	group.add(button);
	buttonWrapper.add(button);

	/* Create a radio button the horizontally split the split pane. */
	button = new JRadioButton("Horizontally split");
	button.setMnemonic('r");
	button.setSelected(true);
	button.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent e) {
		splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
	    }
	});
	group.add(button);
	buttonWrapper.add(button);

	/* Create a check box as to whether or not the split pane continually
	   lays out the component when dragging. */
	JCheckBox checkBox = new JCheckBox("Continuous Layout");
	checkBox.setMnemonic('C");
	checkBox.setSelected(true);

	checkBox.addChangeListener(new ChangeListener() {
	    public void stateChanged(ChangeEvent e) {
		splitPane.setContinuousLayout(((JCheckBox)e.getSource()).isSelected());
	    }
	});
	buttonWrapper.add(checkBox);
	wrapper.add(buttonWrapper);

	/* Create a text field to change the divider size. */
	Box                      tfWrapper;
	JTextField               tf;
	JLabel                   label;

	tf = new JTextField();
        tf.setText(new Integer(splitPane.getDividerSize()).toString());
	tf.setColumns(5);
	tf.getAccessibleContext().setAccessibleName("Divider Size");
	tf.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent e) {
		String           value = ((JTextField)e.getSource()).getText();
		int              newSize;

		try {
		    newSize = Integer.parseInt(value);
		} catch (Exception ex) {
		    newSize = -1;
		}
		if(newSize > 0)
		    splitPane.setDividerSize(newSize);
		else
		    JOptionPane.showMessageDialog(splitPane, "Invalid Divider Size", "Error", JOptionPane.ERROR_MESSAGE);
	    }
	});
	label = new JLabel("Divider Size");
	tfWrapper = new Box(BoxLayout.X_AXIS);
	tfWrapper.add(label);
	tfWrapper.add(Box.createHorizontalStrut(10));
	tfWrapper.add(tf);
        label.setLabelFor(tf);
	label.setDisplayedMnemonic('z");
	tfWrapper.add(Box.createHorizontalStrut(Short.MAX_VALUE));
	wrapper.add(tfWrapper);

	/* Create a text field that will change the preferred/minimum size
	   of the left component. */
	tf = new JTextField(String.valueOf(leftGrid.getPreferredSize().width));
	tf.setColumns(5);
	tf.getAccessibleContext().setAccessibleName("First Component minimum size");
	tf.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent e) {
		String           value = ((JTextField)e.getSource()).getText();
		int              newSize;

		try {
		    newSize = Integer.parseInt(value);
		} catch (Exception ex) {
		    newSize = -1;
		}
		if(newSize > 10)
		    leftGrid.setPreferredSize(newSize);
		else
		    JOptionPane.showMessageDialog(splitPane, "Invalid Minimum Size, must be greater than 10", "Error", JOptionPane.ERROR_MESSAGE);
	    }
	});
	label = new JLabel("First Components Minimum Size");
	tfWrapper = new Box(BoxLayout.X_AXIS);
	tfWrapper.add(label);
	tfWrapper.add(Box.createHorizontalStrut(10));
	tfWrapper.add(tf);
	tfWrapper.add(Box.createHorizontalStrut(Short.MAX_VALUE));
        label.setLabelFor(tf);
	label.setDisplayedMnemonic('i");
	wrapper.add(tfWrapper);
	
	/* Create a text field that will change the preferred/minimum size
	   of the right component. */
	tf = new JTextField(String.valueOf(rightGrid.getPreferredSize().
					   width));
	tf.setColumns(5);
	tf.getAccessibleContext().setAccessibleName("Second Component minimum size");
	tf.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent e) {
		String           value = ((JTextField)e.getSource()).getText();
		int              newSize;

		try {
		    newSize = Integer.parseInt(value);
		} catch (Exception ex) {
		    newSize = -1;
		}
		if(newSize > 10)
		    rightGrid.setPreferredSize(newSize);
		else
		    JOptionPane.showMessageDialog(splitPane, "Invalid Minimum Size, must be greater than 10", "Error", JOptionPane.ERROR_MESSAGE);
	    }
	});
	label = new JLabel("Second Components Minimum Size");
	tfWrapper = new Box(BoxLayout.X_AXIS);
	tfWrapper.add(label);
	tfWrapper.add(Box.createHorizontalStrut(10));
	tfWrapper.add(tf);
	tfWrapper.add(Box.createHorizontalStrut(Short.MAX_VALUE));
        label.setLabelFor(tf);
	label.setDisplayedMnemonic('n");
	wrapper.add(tfWrapper);

	add(wrapper, BorderLayout.SOUTH);
    
protected voidcreateSplitPane()
Creates the JSplitPane.

	leftGrid = new GridComponent(4);
	leftGrid.setPreferredSize(10);
	rightGrid = new GridComponent(4);
	rightGrid.setPreferredSize(10);
	splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftGrid,
				   rightGrid);
	splitPane.setContinuousLayout(true);
	splitPane.setPreferredSize(new Dimension(400, 100));
	splitPane.getAccessibleContext().setAccessibleName("Split pane example");
	add(splitPane, BorderLayout.CENTER);