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

JTable, deletion of last row freezes GUI

    XMLWordPrintable

Details

    Description

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      In a JTable with many rows, the deletion of the last row freeze the GUI for seconds. The last row must be visible in the JTable to freeze the GUI.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      see example source code


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package de.test;

      import java.awt.BorderLayout;
      import java.awt.Container;
      import java.awt.Dimension;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.util.Vector;

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JScrollBar;
      import javax.swing.JScrollPane;
      import javax.swing.JTable;
      import javax.swing.SwingUtilities;
      import javax.swing.table.DefaultTableModel;

      public class Application
      {
        private Application()
        {
          SwingUtilities.invokeLater(new Runnable()
          {
            public void run()
            {
              JFrame frame = new JFrame("LastRowTest");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              Vector columns = new Vector();
              columns.add("Row");
              Vector data = new Vector();
              final int ROWCOUNT = 200000;
              for (int i = 0; i < ROWCOUNT; i++)
              {
                Vector row = new Vector();
                row.add("" + i);
                data.add(row);
              }

              final JTable table = new JTable();
              final DefaultTableModel tm = new DefaultTableModel(data, columns);
              table.setModel(tm);
              table.setPreferredScrollableViewportSize(new Dimension(500, 150));

              JScrollPane scrollPane = new JScrollPane(table);

              Container contentPane = frame.getContentPane();
              contentPane.add(scrollPane, BorderLayout.CENTER);

              JButton rmLastBtn = new JButton("Remove Last");
              rmLastBtn.addActionListener(new ActionListener()
              {
                public void actionPerformed(ActionEvent ae)
                {
                  tm.removeRow(tm.getRowCount() - 1);
                  //table.repaint();
                }
              });
              contentPane.add(rmLastBtn, BorderLayout.WEST);

              frame.pack();
              frame.setVisible(true);
              JScrollBar scBar = scrollPane.getVerticalScrollBar();
              scBar.setValue(scBar.getMaximum());
            }
          });

        }

        public static void main(String[] args)
        {
          Application app = new Application();
        }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      if u do a table.repaint() after tm.removeRow(tm.getRowCount() - 1);
      the freeze does not happen.

      Attachments

        Activity

          People

            Unassigned Unassigned
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: