Java by API/javax.swing/JSplitPane
Версия от 17:43, 31 мая 2010; (обсуждение)
Содержание
- 1 JSplitPane: addHierarchyListener(HierarchyListener l)
- 2 JSplitPane: getBottomComponent()
- 3 JSplitPane: getDividerLocation()
- 4 JSplitPane: getLeftComponent()
- 5 JSplitPane: getRightComponent()
- 6 JSplitPane: getTopComponent()
- 7 JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY
- 8 JSplitPane: resetToPreferredSizes()
- 9 JSplitPane: setContinuousLayout(boolean newContinuousLayout)
- 10 JSplitPane: setDividerLocation(double proportionalLocation)
- 11 JSplitPane: setDividerSize(int newSize)
- 12 JSplitPane: setLeftComponent(Component comp)
- 13 JSplitPane: setOneTouchExpandable(boolean newValue)
- 14 JSplitPane: setOrientation(JSplitPane.HORIZONTAL_SPLIT)
- 15 JSplitPane: setResizeWeight(double value)
- 16 JSplitPane: setRightComponent(Component comp)
- 17 JSplitPane.VERTICAL_SPLIT
- 18 new JSplitPane(int newOrientation, Component newLeftComponent, Component newRightComponent)
JSplitPane: addHierarchyListener(HierarchyListener l)
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);
}
}
JSplitPane: getBottomComponent()
import javax.swing.JButton;
import javax.swing.JSplitPane;
public class Main {
public static void main(String[] argv) throws Exception {
JButton leftComponent = new JButton("left");
JButton rightComponent = new JButton("right");
JButton topComponent = new JButton("top");
JButton bottomComponent = new JButton("bottom");
JSplitPane hpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftComponent, rightComponent);
JSplitPane vpane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topComponent, bottomComponent);
leftComponent = (JButton) hpane.getLeftComponent();
rightComponent = (JButton) hpane.getRightComponent();
topComponent = (JButton) vpane.getTopComponent();
bottomComponent = (JButton) vpane.getBottomComponent();
hpane.setLeftComponent(topComponent);
hpane.setRightComponent(bottomComponent);
vpane.setTopComponent(leftComponent);
vpane.setBottomComponent(rightComponent);
}
}
JSplitPane: getDividerLocation()
import java.awt.BorderLayout;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSplitPane;
public class MainClass {
public static void main(String args[]) throws Exception {
JFrame frame = new JFrame("Property Split");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setTopComponent(new JLabel("www.jexp.ru"));
splitPane.setBottomComponent(new JLabel("www.jexp.ru"));
PropertyChangeListener propertyChangeListener =
new PropertyChangeListener() {
public void propertyChange (PropertyChangeEvent changeEvent) {
JSplitPane sourceSplitPane = (JSplitPane)changeEvent.getSource();
String propertyName = changeEvent.getPropertyName();
if (propertyName.equals(
JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY)) {
int current = sourceSplitPane.getDividerLocation();
System.out.println ("Current: " + current);
Integer last = (Integer)changeEvent.getNewValue();
System.out.println ("Last: " + last);
Integer priorLast = (Integer)changeEvent.getOldValue();
System.out.println ("Prior last: " + priorLast);
}
}
};
// Attach listener
splitPane.addPropertyChangeListener(propertyChangeListener);
frame.add(splitPane, BorderLayout.CENTER);
frame.setSize(300, 150);
frame.setVisible(true);
}
}
JSplitPane: getLeftComponent()
import javax.swing.JButton;
import javax.swing.JSplitPane;
public class Main {
public static void main(String[] argv) throws Exception {
JButton leftComponent = new JButton("left");
JButton rightComponent = new JButton("right");
JButton topComponent = new JButton("top");
JButton bottomComponent = new JButton("bottom");
JSplitPane hpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftComponent, rightComponent);
JSplitPane vpane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topComponent, bottomComponent);
leftComponent = (JButton) hpane.getLeftComponent();
rightComponent = (JButton) hpane.getRightComponent();
topComponent = (JButton) vpane.getTopComponent();
bottomComponent = (JButton) vpane.getBottomComponent();
hpane.setLeftComponent(topComponent);
hpane.setRightComponent(bottomComponent);
vpane.setTopComponent(leftComponent);
vpane.setBottomComponent(rightComponent);
}
}
JSplitPane: getRightComponent()
import javax.swing.JButton;
import javax.swing.JSplitPane;
public class Main {
public static void main(String[] argv) throws Exception {
JButton leftComponent = new JButton("left");
JButton rightComponent = new JButton("right");
JButton topComponent = new JButton("top");
JButton bottomComponent = new JButton("bottom");
JSplitPane hpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftComponent, rightComponent);
JSplitPane vpane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topComponent, bottomComponent);
leftComponent = (JButton) hpane.getLeftComponent();
rightComponent = (JButton) hpane.getRightComponent();
topComponent = (JButton) vpane.getTopComponent();
bottomComponent = (JButton) vpane.getBottomComponent();
hpane.setLeftComponent(topComponent);
hpane.setRightComponent(bottomComponent);
vpane.setTopComponent(leftComponent);
vpane.setBottomComponent(rightComponent);
}
}
JSplitPane: getTopComponent()
import javax.swing.JButton;
import javax.swing.JSplitPane;
public class Main {
public static void main(String[] argv) throws Exception {
JButton leftComponent = new JButton("left");
JButton rightComponent = new JButton("right");
JButton topComponent = new JButton("top");
JButton bottomComponent = new JButton("bottom");
JSplitPane hpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftComponent, rightComponent);
JSplitPane vpane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topComponent, bottomComponent);
leftComponent = (JButton) hpane.getLeftComponent();
rightComponent = (JButton) hpane.getRightComponent();
topComponent = (JButton) vpane.getTopComponent();
bottomComponent = (JButton) vpane.getBottomComponent();
hpane.setLeftComponent(topComponent);
hpane.setRightComponent(bottomComponent);
vpane.setTopComponent(leftComponent);
vpane.setBottomComponent(rightComponent);
}
}
JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY
import java.awt.BorderLayout;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSplitPane;
public class MainClass {
public static void main(String args[]) throws Exception {
JFrame frame = new JFrame("Property Split");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setTopComponent(new JLabel("www.jexp.ru"));
splitPane.setBottomComponent(new JLabel("www.jexp.ru"));
PropertyChangeListener propertyChangeListener =
new PropertyChangeListener() {
public void propertyChange (PropertyChangeEvent changeEvent) {
JSplitPane sourceSplitPane = (JSplitPane)changeEvent.getSource();
String propertyName = changeEvent.getPropertyName();
if (propertyName.equals(
JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY)) {
int current = sourceSplitPane.getDividerLocation();
System.out.println ("Current: " + current);
Integer last = (Integer)changeEvent.getNewValue();
System.out.println ("Last: " + last);
Integer priorLast = (Integer)changeEvent.getOldValue();
System.out.println ("Prior last: " + priorLast);
}
}
};
// Attach listener
splitPane.addPropertyChangeListener(propertyChangeListener);
frame.add(splitPane, BorderLayout.CENTER);
frame.setSize(300, 150);
frame.setVisible(true);
}
}
JSplitPane: resetToPreferredSizes()
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);
}
}
JSplitPane: setContinuousLayout(boolean newContinuousLayout)
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);
}
}
JSplitPane: setDividerLocation(double proportionalLocation)
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);
}
}
JSplitPane: setDividerSize(int newSize)
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSplitPane;
public class Main{
public static void main(String[] a) {
int HORIZSPLIT = JSplitPane.HORIZONTAL_SPLIT;
int VERTSPLIT = JSplitPane.VERTICAL_SPLIT;
boolean continuousLayout = true;
JLabel label1 = new JLabel("a");
JLabel label2 = new JLabel("b");
JLabel label3 = new JLabel("c");
JSplitPane splitPane1 = new JSplitPane(VERTSPLIT, continuousLayout, label1, label2);
splitPane1.setOneTouchExpandable(true);
splitPane1.setDividerSize(2);
splitPane1.setDividerLocation(0.5);
JSplitPane splitPane2 = new JSplitPane(HORIZSPLIT, splitPane1, label3);
splitPane2.setOneTouchExpandable(true);
splitPane2.setDividerLocation(0.4);
splitPane2.setDividerSize(2);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(splitPane2);
frame.pack();
frame.setVisible(true);
}
}
JSplitPane: setLeftComponent(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);
}
}
JSplitPane: setOneTouchExpandable(boolean newValue)
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);
}
}
JSplitPane: setOrientation(JSplitPane.HORIZONTAL_SPLIT)
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JSplitPane;
public class MainClass {
public static void main(String args[]) {
JFrame frame = new JFrame("JSplitPane Sample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSplitPane splitPane = new JSplitPane();
splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
frame.add(splitPane, BorderLayout.CENTER);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
JSplitPane: setResizeWeight(double value)
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSplitPane;
public class MainClass {
public static void main(String args[]) throws Exception {
JFrame frame = new JFrame("Property Split");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setResizeWeight(1.0);
splitPane.setTopComponent(new JLabel("www.jexp.ru"));
splitPane.setBottomComponent(new JLabel("www.jexp.ru"));
frame.add(splitPane, BorderLayout.CENTER);
frame.setSize(300, 150);
frame.setVisible(true);
}
}
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);
}
}
JSplitPane.VERTICAL_SPLIT
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);
}
}
new JSplitPane(int newOrientation, Component newLeftComponent, Component newRightComponent)
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
public class MainClass extends JFrame {
static String sometext = "Text Text Text Text Text Text Text Text Text Text Text Text ";
public MainClass() {
super("Simple SplitPane Frame");
setSize(450, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JTextArea jt1 = new JTextArea(sometext);
JTextArea jt2 = new JTextArea(sometext);
jt1.setLineWrap(true);
jt2.setLineWrap(true);
jt1.setMinimumSize(new Dimension(150, 150));
jt2.setMinimumSize(new Dimension(150, 150));
jt1.setPreferredSize(new Dimension(250, 200));
JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jt1, jt2);
getContentPane().add(sp, BorderLayout.CENTER);
}
public static void main(String args[]) {
MainClass ssb = new MainClass();
ssb.setVisible(true);
}
}