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.

esizing a column affects the width of the last column. With<br />

AUTO_RESIZE_SUBSEQUENT_COLUMNS, resizing a column affects the<br />

widths of all the subsequent columns. With<br />

AUTO_RESIZE_NEXT_COLUMN, resizing a column affects the widths of<br />

the next columns. With AUTO_RESIZE_ALL_COLUMNS, resizing a column<br />

affects the widths of all the columns.<br />

Listing 40.2 gives an example that demonstrates the use of<br />

several JTable properties. The example creates a table and allows<br />

the user <strong>to</strong> choose an Au<strong>to</strong> Resize Mode, specify the row height<br />

and margin, and indicate whether the grid is shown. A sample run<br />

of the program is shown in Figure 40.4.<br />

Figure 40.4<br />

You can specify an au<strong>to</strong>resizing mode, the table’s row height and row<br />

margin, and whether <strong>to</strong> show the grid in the table.<br />

Listing 40.2 TablePropertiesDemo.java<br />

<br />

<br />

<br />

<br />

<br />

<br />

<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.event.*;<br />

5<br />

6 public class TablePropertiesDemo extends JApplet {<br />

7 // Create table column names<br />

8 private String[] columnNames =<br />

9 {"Country", "Capital", "Population in Millions", "Democracy"};<br />

10<br />

11 // Create table data<br />

12 private Object[][] rowData = {<br />

13 {"USA", "Washing<strong>to</strong>n DC", 280, true},<br />

14 {"Canada", "Ottawa", 32, true},<br />

15 {"United Kingdom", "London", 60, true},<br />

16 {"Germany", "Berlin", 83, true},<br />

17 {"France", "Paris", 60, true},<br />

18 {"Norway", "Oslo", 4.5, true},<br />

19 {"India", "New Delhi", 1046, true}<br />

5

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

Saved successfully!

Ooh no, something went wrong!