Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4510857

Some PLAFs display no JTable column headings if the first heading is blank

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 1.3.1
    • client-libs

    Description



      Name: gm110360 Date: 10/04/2001


      J:\mscheper\7637\BIN>java -version
      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      When the leftmost column heading in a JTable is blank (i.e. getColumnHeading(0)
      returns ""), the rendered table displays no column headings at all for some
      pluggable looks and feelings (PLAFs).

      This code demonstrates the problem:

      ---

      import javax.swing.JTable;
      import javax.swing.JScrollPane;
      import javax.swing.JPanel;
      import javax.swing.JFrame;
      import javax.swing.UIManager;
      import java.awt.*;
      import java.awt.event.*;

      /**
       * Shows a {@link javax.swing.JTable JTable} bug.
       * <p>
       * This code is based on the version of <code>SimpleTableDemo</code> that is
      available for download on
       * <a
      href="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html">Sun
      's
       * "How to Use Tables"</a> web page. It has undergone the following
      modifications:
       * <ol>
       * <li> The first column has a blank heading (the crux of the problem)
       * <li> The {@link #main} method has been modified to show tables using
       * different pluggable looks and feelings
       * </ol>
       *
       * @author Mik Scheper, <a href="http://www.iii.com/">Innovative Interfaces,
      Inc.</a>
       */
      public class SimpleTableDemo extends JFrame {
          private boolean DEBUG = true;

          public SimpleTableDemo(String sFrameTitle) {
              super(sFrameTitle);

              Object[][] data = {
                  {"Mary", "Campione",
                   "Snowboarding", new Integer(5), new Boolean(false)},
                  {"Alison", "Huml",
                   "Rowing", new Integer(3), new Boolean(true)},
                  {"Kathy", "Walrath",
                   "Chasing toddlers", new Integer(2), new Boolean(false)},
                  {"Mark", "Andrews",
                   "Speed reading", new Integer(20), new Boolean(true)},
                  {"Angela", "Lih",
                   "Teaching high school", new Integer(4), new Boolean(false)}
              };

              String[] columnNames = {"",
                                      "Last Name",
                                      "Sport",
                                      "# of Years",
                                      "Vegetarian"};

              final JTable table = new JTable(data, columnNames);
              table.setPreferredScrollableViewportSize(new Dimension(500, 70));

              if (DEBUG) {
                  table.addMouseListener(new MouseAdapter() {
                      public void mouseClicked(MouseEvent e) {
                          printDebugData(table);
                      }
                  });
              }

              //Create the scroll pane and add the table to it.
              JScrollPane scrollPane = new JScrollPane(table);

              //Add the scroll pane to this window.
              getContentPane().add(scrollPane, BorderLayout.CENTER);

              addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  }
              });
          }

          private void printDebugData(JTable table) {
              int numRows = table.getRowCount();
              int numCols = table.getColumnCount();
              javax.swing.table.TableModel model = table.getModel();

              System.out.println("Value of data: ");
              for (int i=0; i < numRows; i++) {
                  System.out.print(" row " + i + ":");
                  for (int j=0; j < numCols; j++) {
                      System.out.print(" " + model.getValueAt(i, j));
                  }
                  System.out.println();
              }
              System.out.println("--------------------------");
          }

      public static void main(String[] args)
      {
      SimpleTableDemo defaultPLAF = new SimpleTableDemo("default");
      defaultPLAF.pack();
      defaultPLAF.setVisible(true);

      try
      {
      UIManager.setLookAndFeel
      ("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
      }
      catch (Exception oException)
      {
      oException.printStackTrace();
      }
      SimpleTableDemo motifPLAF = new SimpleTableDemo
      ("MotifLookAndFeel");
      motifPLAF.pack();
      motifPLAF.setLocation(new Point((int)(defaultPLAF.getLocation
      ().getX()+defaultPLAF.getSize().getWidth()), (int)(defaultPLAF.getLocation
      ().getY())));
      motifPLAF.setVisible(true);

      try
      {
      UIManager.setLookAndFeel
      ("javax.swing.plaf.metal.MetalLookAndFeel");
      }
      catch (Exception oException)
      {
      oException.printStackTrace();
      }
      SimpleTableDemo metalPLAF = new SimpleTableDemo
      ("WindowsLookAndFeel");
      metalPLAF.pack();
      metalPLAF.setLocation(new Point((int)(defaultPLAF.getLocation
      ().getX()), (int)(defaultPLAF.getLocation().getY()+defaultPLAF.getSize
      ().getHeight())));
      metalPLAF.setVisible(true);

      try
      {
      UIManager.setLookAndFeel
      ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
      }
      catch (Exception oException)
      {
      oException.printStackTrace();
      }
      SimpleTableDemo windowsPLAF = new SimpleTableDemo
      ("MetalLookAndFeel");
      windowsPLAF.pack();
      windowsPLAF.setLocation(new Point((int)(defaultPLAF.getLocation
      ().getX()+defaultPLAF.getSize().getWidth()), (int)(defaultPLAF.getLocation
      ().getY()+defaultPLAF.getSize().getHeight())));
      windowsPLAF.setVisible(true);
      }
      }
      (Review ID: 133102)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              dmcduffisunw Dale Mcduffie (Inactive)
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: