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

JTable header rendering problem (after setting preferred size)

    XMLWordPrintable

    Details

      Description

      Name: bsC130419 Date: 06/21/2001


      Found in: J2SE 1.3.0 (build 1.3.0-C)
      Also in: J2SE 1.4.0-beta (build 1.4.0-beta-b65)

      This appears to be a problem with the rendering of JTable headers, such that
      the header does not redraw properly when the table and header are horizontally
      scrolled.

      Steps:
      1) Create a JTable and a simple model with several columns.
      2) Set the JTable setAutoResizeMode to JTable.AUTO_RESIZE_OFF.
      3) Add the JTable to a JScrollPane.
      4) Manually set the preferred size of the JTable's header.
      5) Place the whole lot in a JFrame and display it.

      Now, if you resize the window so that some of the JTable's columns do not fit
      you get a scroll bar as expected. Dragged the scroll bar to the right; the
      header does not repaint the headers for the new columns that have become
      visible (though the columns themselves look okay). The header display becomes
      corrupt.

      It appears as though the all pixels for the previously visible part of the
      header have been shifted left okay, but the right-most fragment of the old
      visible header region has been redrawn on the far right, rather than a new
      rectangular section representing the part of the header that has become visible.

      The following sample code reproduces the problem in 1.3.0 and 1.4.0 beta.

      -----

      import java.awt.*;
      import javax.swing.*;
      import javax.swing.table.*;

      public class TableHeaderBug extends JFrame {

          private JTable jTable = new JTable();
          private JScrollPane jscpScroll;

          public TableHeaderBug() {
              jTable.setModel(new MyTableModel());
              jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
              jscpScroll = new JScrollPane(jTable);
              // Manually set preferred size of header...
              jTable.getTableHeader().setPreferredSize(
                  new Dimension(jTable.getSize().width, 40)
              );
              setContentPane(jscpScroll);
              setSize(640, 480);
              setVisible(true);
          }

          public static void main(String[] args) {
              new TableHeaderBug();
          }

      }

      class MyTableModel extends AbstractTableModel {

          public int getRowCount() { return 100; }
          public int getColumnCount() { return 8; }
          public Object getValueAt(int r, int c) {
              return new Integer((r+1)*(c+1));
          }
          public String getColumnName(int c) {
              return "times by "+(c+1);
          }

      }
      (Review ID: 126803)
      ======================================================================
      *** (#1 of 1): 2004-09-29 09:45:58 MSD ###@###.###
      *** Last Edit: 2006-03-10 08:42:42 MSK ###@###.###

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              vkarnauk Vladislav Karnaukhov
              Reporter:
              alexp Alexander Potochkin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: