Copyright Derek O'Reilly, Dundalk Institute of Technology (DkIT), Dundalk, Co. Louth, Ireland.
SplitPane Example (Run Applet)
import java.awt.*;
import javax.swing.*;
public class SplitPaneDemo extends JApplet
{
@Override
public void init()
{
this.setContentPane(new View());
}
public class View extends JPanel
{
public View()
{
super();
final JSplitPane splitPane;
// create two scrolling textAreas
final JScrollPane textArea1 = new JScrollPane(new JTextArea("Text area 1"));
final JScrollPane textArea2 = new JScrollPane(new JTextArea("Text area 2"));
// put the two textArea scrollPanes into a splitPane
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, textArea1, textArea2);
splitPane.setDividerLocation(150); // if setDividerLocation(150) left out, the first
// component will be sized to be as small as possible
// add the splitPane to the applet
this.setLayout(new GridLayout(1, 1));
this.add(splitPane);
}
}
}
As with all other Pane components, an applet's View can Extend JSplitPane. This is shown in the code below.
SplitPane_Extends_Demo Example (Run Applet)
import javax.swing.*;
public class SplitPane_Extends_Demo extends JApplet
{
@Override
public void init()
{
this.setContentPane(new View());
}
public class View extends JSplitPane
{
public View()
{
super();
// create two scrolling textAreas
final JScrollPane textArea1 = new JScrollPane(new JTextArea("Text area 1"));
final JScrollPane textArea2 = new JScrollPane(new JTextArea("Text area 2"));
this.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
this.setDividerLocation(150);
this.setLeftComponent(textArea1);
this.setRightComponent(textArea2);
}
}
}
SplitPane_OneTouch_Demo Example (Run Applet)
import java.awt.*;
import javax.swing.*;
public class SplitPane_OneTouch_Demo extends JApplet
{
@Override
public void init()
{
this.setContentPane(new View());
}
public class View extends JPanel
{
public View()
{
super();
final JSplitPane splitPane;
// create two scrolling textAreas
final JScrollPane textArea1 = new JScrollPane(new JTextArea("Text area 1"));
final JScrollPane textArea2 = new JScrollPane(new JTextArea("Text area 2"));
// put the two textArea scrollPanes into a splitPane
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, textArea1, textArea2);
splitPane.setDividerLocation(150);
// if setDividerLocation(150) left out, the first
// component will be sized to be as small as possible
// enable one touch compression and expansion of splitPane components
splitPane.setOneTouchExpandable(true);
// add the splitPane to the applet
this.setLayout(new GridLayout(1, 1));
this.add(splitPane);
}
}
}
SplitPane_Multiple_Demo Example (Run Applet)
import java.awt.*;
import javax.swing.*;
public class SplitPane_Multiple_Demo extends JApplet
{
@Override
public void init()
{
this.setContentPane(new View());
}
public class View extends JPanel
{
public View()
{
super();
final JSplitPane mainSplitPane;
final JSplitPane subSplitPane;
// create three scrolling textAreas
final JScrollPane textArea1 = new JScrollPane(new JTextArea("Text area 1"));
final JScrollPane textArea2 = new JScrollPane(new JTextArea("Text area 2"));
final JScrollPane textArea3 = new JScrollPane(new JTextArea("Text area 3"));
// put the two rightmost textAreas into splitPaneRight
subSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, textArea2, textArea3);
// put the leftmost textArea and subSplitPane into the mainSplitPane
mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, textArea1, subSplitPane);
// enable one touch compression and expansion of splitPane components
mainSplitPane.setOneTouchExpandable(true);
subSplitPane.setOneTouchExpandable(true);
// add the splitPane to the applet
this.setLayout(new GridLayout(1, 1));
this.add(mainSplitPane);
}
}
}
Copyright Derek O' Reilly, Dundalk Institute of Technology (DkIT), Dundalk, Co. Louth, Ireland.