19.09.2015 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

in an ImageViewer. Set the dimension of an image viewer <strong>to</strong> 32<br />

by 32, as shown in Figure 39.30. Revise Listing 39.10 <strong>to</strong> test<br />

the new cus<strong>to</strong>m cell renderer.<br />

ImageViewer<br />

JLabel<br />

Same image<br />

as in the list<br />

Figure 39.30<br />

ImageViewer is used <strong>to</strong> render the image in the list.<br />

39.8*<br />

(Delete selected items in a list using the DELETE key) Modify Listing<br />

39.10, ListCellRendererDemo.java, <strong>to</strong> delete selected items from<br />

the list using the DELETE key. After some items are deleted<br />

from the list, the index of a selected item in the list does<br />

not match the index of the item in the bigIcons array. As a<br />

result, you cannot use the image icon in the bigIcons array <strong>to</strong><br />

display the image <strong>to</strong> the right side of the split pane. Revise<br />

the program <strong>to</strong> retrieve the icon from the selected item in the<br />

list and display it, as shown in Figure 39.31.<br />

JLabel<br />

Same image<br />

as in the list<br />

Figure 39.31<br />

Images in the list are also used for display in the label placed in the<br />

right side of a split pane.<br />

39.9**<br />

(Render figures) Create a program that shows a list of geometrical<br />

shapes along with a label in an instance of JList, as shown in<br />

Figure 39.32(a). Display the selected figure in a panel when<br />

selecting a figure from the list. The figures can be drawn<br />

using the FigurePanel class in Listing 14.5, FigurePanel.java.<br />

(a)<br />

(b)<br />

Figure 39.32<br />

43

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

Saved successfully!

Ooh no, something went wrong!