Java Reference
In-Depth Information
17.
private static
String picturePath = "./its/TestData/";
18.
19.
public
SplitPaneFrame()
20.
{
21.
this
.setSize(800,400);
22.
JSplitPane splitPane1 =
new
JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
23.
JSplitPane splitPane2 =
new
JSplitPane(JSplitPane.VERTICAL_SPLIT);
24.
splitPane1.setOneTouchExpandable(
true
);
25.
splitPane1.setDividerSize(20);
26.
27.
this
.getContentPane().add(splitPane1,BorderLayout.CENTER);
28.
splitPane1.setRightComponent(splitPane2);
29.
30.
picture1 =
new
ImageIcon(picturePath+"/Orange.png");
31.
picture2 =
new
ImageIcon(picturePath+"/Banana.png");
32.
33.
picLabel1 =
new
JLabel(picture1);
34.
JScrollPane sp2a =
new
JScrollPane(picLabel1);
35.
splitPane2.setTopComponent(sp2a);
36.
picLabel2 =
new
JLabel(picture2);
37.
JScrollPane sp2b =
new
JScrollPane(picLabel2);
38.
splitPane2.setBottomComponent(sp2b);
39.
splitPane2.setDividerLocation(150);
40.
splitPane1.setDividerLocation(100);
41.
42.
File startFile =
new
File(picturePath);
43.
list =
new
JList(startFile.listFiles());
44.
JScrollPane sp =
new
JScrollPane(list);
45.
splitPane1.setLeftComponent(sp);
46.
47.
okButton =
new
JButton("OK");
48.
okButton.setBackground(Color.cyan);
49.
this
.getContentPane().add(okButton,BorderLayout.SOUTH);
50.
okButton.addActionListener(
new
ActionListener()
51.
{
52.
public void
actionPerformed(ActionEvent e)
53.
{
54.
String filename = ((File)(list.getSelectedValue())).getPath();
55.
if
((filename.endsWith(".png")) || (filename.endsWith(".jpg")) ||
56.
(filename.endsWith(".PNG")) || (filename.endsWith(".JPG")))
57.
{
58.
picLabel2.setIcon(
new
ImageIcon(filename));
59.
}
60.
}
61.
});
62.
}
63.
Search WWH ::
Custom Search