19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

To set a corner <strong>com</strong>ponent, you can use the setCorner(String key,<br />

Component corner) method. The legal values for the key are:<br />

JScrollPane.LOWER_LEFT_CORNER<br />

JScrollPane.LOWER_RIGHT_CORNER<br />

JScrollPane.UPPER_LEFT_CORNER<br />

JScrollPane.UPPER_RIGHT_CORNER<br />

Listing 37.6 shows an example that displays a map in a label and<br />

places the label in a scroll pane so that a large map can be scrolled.<br />

The program lets you choose a map from a <strong>com</strong>bo box and display it in<br />

the scroll pane, as shown in Figure 37.12.<br />

Figure 37.12<br />

The scroll pane can be used <strong>to</strong> scroll contents au<strong>to</strong>matically.<br />

Listing 37.6 ScrollMap.java<br />

<br />

<br />

<br />

<br />

<br />

1 import java.awt.*;<br />

2 import java.awt.event.*;<br />

3 import javax.swing.*;<br />

4 import javax.swing.border.*;<br />

5<br />

6 public class ScrollMap extends JApplet {<br />

7 // Create images in labels<br />

8 private JLabel lblIndianaMap = new JLabel(<br />

9 new ImageIcon(getClass().getResource("image/indianaMap.gif")));<br />

10 private JLabel lblOhioMap = new JLabel(<br />

11 new ImageIcon(getClass().getResource("/image/ohioMap.gif")));<br />

12<br />

13 // Create a scroll pane <strong>to</strong> scroll map in the labels<br />

14 private JScrollPane jspMap = new JScrollPane(lblIndianaMap);<br />

15<br />

16 public ScrollMap() {<br />

17 // Create a <strong>com</strong>bo box for selecting maps<br />

23

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!