-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathSplitPaneFrame.java
More file actions
56 lines (42 loc) · 1.76 KB
/
Copy pathSplitPaneFrame.java
File metadata and controls
56 lines (42 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package splitPane;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
/**
* This frame consists of two nested split panes to demonstrate planet images and data.
*/
class SplitPaneFrame extends JFrame
{
private static final int DEFAULT_WIDTH = 300;
private static final int DEFAULT_HEIGHT = 300;
private Planet[] planets = { new Planet("Mercury", 2440, 0), new Planet("Venus", 6052, 0),
new Planet("Earth", 6378, 1), new Planet("Mars", 3397, 2),
new Planet("Jupiter", 71492, 16), new Planet("Saturn", 60268, 18),
new Planet("Uranus", 25559, 17), new Planet("Neptune", 24766, 8),
new Planet("Pluto", 1137, 1), };
public SplitPaneFrame()
{
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
// set up components for planet names, images, descriptions
final JList<Planet> planetList = new JList<>(planets);
final JLabel planetImage = new JLabel();
final JTextArea planetDescription = new JTextArea();
planetList.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent event)
{
Planet value = (Planet) planetList.getSelectedValue();
// update image and description
planetImage.setIcon(value.getImage());
planetDescription.setText(value.getDescription());
}
});
// set up split panes
JSplitPane innerPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, planetList, planetImage);
innerPane.setContinuousLayout(true);
innerPane.setOneTouchExpandable(true);
JSplitPane outerPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, innerPane,
planetDescription);
add(outerPane, BorderLayout.CENTER);
}
}