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

Exception during refresh of JTable after removeColumn

    Details

      Description

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

      ADDITIONAL OS VERSION INFORMATION :
      Linux ubuntu-pc 2.6.20-16-generic #2 SMP i686 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      When removing a column from a JTable using JTable.removeColumn, an ArrayIndexOutOfBoundsException occurs under certain circumstances (see below).

      The L&F used is GTK+.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - Right-click on the right column header ("B") to open the popup menu. The popup menu must be opened far enough to the right, so that it is not completely inside the bounds of the frame.
      - Select the menu item to remove the column. The exception should occur.

      The bug does not occur if
      - the popup menu opens completely inside the bounds of the frame, or
      - the popup menu is opened on mouseReleased instead of mousePressed, or
      - Metal L&F is used instead of GTK+.
      - Left-click to show popup menu.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      no exception
      ACTUAL -
      ArrayIndexOutOfBoundsException

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
      at java.util.Vector.elementAt(Vector.java:430)
      at javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:277)
      at javax.swing.JTable.getCellRenderer(JTable.java:5617)
      at javax.swing.plaf.synth.SynthTableUI.paintCell(SynthTableUI.java:604)
      at javax.swing.plaf.synth.SynthTableUI.paintDraggedArea(SynthTableUI.java:579)
      at javax.swing.plaf.synth.SynthTableUI.paintCells(SynthTableUI.java:530)
      at javax.swing.plaf.synth.SynthTableUI.paint(SynthTableUI.java:291)
      at javax.swing.plaf.synth.SynthTableUI.update(SynthTableUI.java:217)
      at javax.swing.JComponent.paintComponent(JComponent.java:763)
      at javax.swing.JComponent.paint(JComponent.java:1027)
      at javax.swing.JComponent.paintToOffscreen(JComponent.java:5122)
      at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:285)
      at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
      at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
      at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
      at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:723)
      at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
      at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
      at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.event.MouseAdapter;
      import java.awt.event.MouseEvent;
      import javax.swing.*;

      public class JTableBug extends javax.swing.JFrame {
          
          /** Creates a new instance of JTableBug */
          public JTableBug() {
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              

              final JTable table = new JTable(new String[][] { { "1", "2" }},
                      new String[] { "A", "B" });
              add(new JScrollPane(table));
              JMenuItem item = new JMenuItem("Remove Column B");
              item.addActionListener(new ActionListener() {
                  
                  public void actionPerformed(ActionEvent event) {
                      table.removeColumn(table.getColumn("B"));
                  }
              });
              final JPopupMenu menu = new JPopupMenu();
              menu.add(item);
              table.getTableHeader().addMouseListener(new MouseAdapter() {
                  public void mousePressed(MouseEvent event) {
                      menu.show(event.getComponent(), event.getX(), event.getY());
                  }
              });
              
              pack();
          }
          
          
          public static void main(String[] args) {
              java.awt.EventQueue.invokeLater( new Runnable() {
                  public void run() {
                      new JTableBug().setVisible(true);
                  }
                  
              });
          }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              peterz Peter Zhelezniakov
              Reporter:
              ryeung Roger Yeung (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: