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

JTableHeader: must not react to mouse if disabled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6u14
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.6.0_14"
      Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
      Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      not important

      A DESCRIPTION OF THE PROBLEM :
      subject says it all (or see code :-)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.JComponent;
      import javax.swing.JFrame;
      import javax.swing.JScrollPane;
      import javax.swing.JTable;
      import javax.swing.SwingUtilities;

      /**
       * JTableHeader must not react to mouseEvents if disabled.
       * Specifically: columns must not be
       * - resizable
       * - draggable
       * - sortable
       *
       * Note that the resizing cursor not showing.
       *
       * @author Jeanette Winzenburg
       */
      public class TableHeaderDisabled {

          private JComponent createContent() {
              JTable table = new JTable(20, 5);
              table.setAutoCreateRowSorter(true);
              table.setEnabled(false);
              table.getTableHeader().setEnabled(false);
              JComponent content = new JScrollPane(table);
              return content;
          }
          
          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      JFrame frame = new JFrame("");
                      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      frame.add(new TableHeaderDisabled().createContent());
                      frame.setLocationRelativeTo(null);
                      frame.pack();
                      frame.setVisible(true);
                  }
              });
          }
          
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :

      nothing except going drastic, like subclassing JTableHeader, remove all mouseListeners on disabling and re-add again on enabling.

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: