JSplitPane: setRightComponent(Component comp) : JSplitPane « javax.swing « Java by API






JSplitPane: setRightComponent(Component comp)

  

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

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

public class MainClass {
  public static void main(String args[]) throws Exception {
    JFrame vFrame = new JFrame("Vertical Split");
    vFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JComponent leftButton = new JButton("Left");
    JComponent rightButton = new JButton("Right");
    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);

    HierarchyListener hierarchyListener = new HierarchyListener() {
      public void hierarchyChanged(HierarchyEvent e) {
        long flags = e.getChangeFlags();
        if ((flags & HierarchyEvent.SHOWING_CHANGED) == HierarchyEvent.SHOWING_CHANGED) {
          splitPane.setDividerLocation(.75);
        }
      }
    };
    splitPane.addHierarchyListener(hierarchyListener);

    vFrame.add(splitPane, BorderLayout.CENTER);
    vFrame.setSize(300, 150);
    vFrame.setVisible(true);
  }

}

           
         
    
  








Related examples in the same category

1.JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY
2.JSplitPane.VERTICAL_SPLIT
3.new JSplitPane(int newOrientation, Component newLeftComponent, Component newRightComponent)
4.JSplitPane: addHierarchyListener(HierarchyListener l)
5.JSplitPane: getBottomComponent()
6.JSplitPane: getDividerLocation()
7.JSplitPane: getLeftComponent()
8.JSplitPane: getRightComponent()
9.JSplitPane: getTopComponent()
10.JSplitPane: resetToPreferredSizes()
11.JSplitPane: setContinuousLayout(boolean newContinuousLayout)
12.JSplitPane: setDividerLocation(double proportionalLocation)
13.JSplitPane: setDividerSize(int newSize)
14.JSplitPane: setLeftComponent(Component comp)
15.JSplitPane: setOneTouchExpandable(boolean newValue)
16.JSplitPane: setOrientation(JSplitPane.HORIZONTAL_SPLIT)
17.JSplitPane: setResizeWeight(double value)