home *** CD-ROM | disk | FTP | other *** search
Java Source | 1999-11-28 | 4.1 KB | 123 lines |
- /*
- * @(#)TableExample.java 1.0 99/11/27
- *
- * Copyright (c) 1999, David Griffiths. All Rights Reserved.
- *
- * This software is the proprietary information of David Griffiths.
- * This source code may not be published or redistributed without the
- * express permission of the author.
- *
- * THE AUTHOR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
- * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
- * PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR SHALL NOT BE LIABLE FOR ANY DAMAGES
- * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
- * THIS SOFTWARE OR ITS DERIVATIVES.
- *
- */
-
- import java.awt.*;
- import java.applet.*;
- import com.sun.java.swing.*;
-
- /**
- * A Swing table example
- */
- public class TableExample extends JApplet {
- public void init() {
-
- JTable tabMain = new JTable(cells, headings);
-
- Font fntTable = new Font("HELVETICA", Font.PLAIN, 12);
- tabMain.setFont(fntTable);
- tabMain.getTableHeader().setFont(fntTable);
-
- // Switch off auto-resize, because it's mad...
- tabMain.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
-
- /*
- * The example code you see in some of the Java
- * documentation suggests you should place a JTable
- * inside a JScrollPane with
- *
- * JScrollPane scrollPane = new JScrollPane(tabMain);
- * getContentPane().add(scrollPane, BorderLayout.CENTER);
- *
- * However, if you do that, Swing will lose its column
- * headings which need to be placed in the JScrollPane's
- * column header view.
- * Fortunately, the JTable class has a very nice static
- * method called "createScrollPaneForTable(...)" that
- * does all this for you.
- */
-
- getContentPane().add(
- JTable.createScrollPaneForTable(tabMain),
- BorderLayout.CENTER
- );
- }
-
- // Some example data follows
-
- String[] headings = {
- "Author",
- "Title",
- "Publisher",
- "ISBN",
- "Description"
- };
-
- Object[][] cells = {
- {"Peter Anders",
- "Envisioning Cyberspace: Designing 3d Electronic Spaces",
- "McGraw-Hill Companies, The", "0070016321",
- "Free of the constraints of physical form and limited..."},
- {"Tom Armstrong",
- "Activex Developer`s SourceBook: With CD-ROM",
- "McGraw-Hill Companies, The", "0070062137",
- "Focusing on design and development of Web-based and..."},
- {"Richard L. Petersen",
- "UNIX Clearly Explained",
- "Academic Press, Incorporated", "0125521308",
- "Unix Clearly Explained is a complete tutorial introduction..."},
- {"Robby Swipe",
- "A smile, a song and a balloon: 30 years of comedy",
- "Biscos Discount Publishers", "0177682456",
- "I'll never forget what the late great Bernie Clifton said to me..."},
- {"Peter Anders",
- "Envisioning Cyberspace: Designing 3d Electronic Spaces",
- "McGraw-Hill Companies, The", "0070016321",
- "Free of the constraints of physical form and limited..."},
- {"Tom Armstrong",
- "Activex Developer`s SourceBook: With CD-ROM",
- "McGraw-Hill Companies, The", "0070062137",
- "Focusing on design and development of Web-based and..."},
- {"Richard L. Petersen",
- "UNIX Clearly Explained",
- "Academic Press, Incorporated", "0125521308",
- "Unix Clearly Explained is a complete tutorial introduction..."},
- {"Robby Swipe",
- "A smile, a song and a balloon: 30 years of comedy",
- "Biscos Discount Publishers", "0177682456",
- "I'll never forget what the late great Bernie Clifton said to me..."},
- {"Peter Anders",
- "Envisioning Cyberspace: Designing 3d Electronic Spaces",
- "McGraw-Hill Companies, The", "0070016321",
- "Free of the constraints of physical form and limited..."},
- {"Tom Armstrong",
- "Activex Developer`s SourceBook: With CD-ROM",
- "McGraw-Hill Companies, The", "0070062137",
- "Focusing on design and development of Web-based and..."},
- {"Richard L. Petersen",
- "UNIX Clearly Explained",
- "Academic Press, Incorporated", "0125521308",
- "Unix Clearly Explained is a complete tutorial introduction..."},
- {"Robby Swipe",
- "A smile, a song and a balloon: 30 years of comedy",
- "Biscos Discount Publishers", "0177682456",
- "I'll never forget what the late great Bernie Clifton said to me..."}
- };
- }
-
-
-