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

JTable on a JScrollPane on a JTabbedPane not painting right

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.3.0
    • client-libs



      Name: stC104175 Date: 05/11/2000


      java version "1.3.0rc2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc2-Y)
      Java HotSpot(TM) Client VM (build 1.3.0rc2-Y, mixed mode)

      I have a JTabbedPane containing a JScrollPane on each of the tabs, and each of
      the JScrollPanes contain a JTable. The number of rows on each of the tables
      differ. For example: on the first tab there is a table (on a scrollpane) with
      one row, on the second tab a table with 4 rows and on the third tab, a table
      with 7 rows.

      Now when the tabbedPane is created, the first tab is shown correctly. When I
      click to see the other tabs with more rows, on each tab only one row is still
      shown. The getRowCount method of the TableModel returns 4 and 7, respectively,
      but only the first row is painted.

      When I am on the second tab and resize the window, the "missing" rows suddenly
      appear. After this, the tables are painted correctly each time.

      If I do not use scrollpanes and add the tables directly to the tabbedpane, it
      works fine.

      The example below works the same incorrect way with both JDK1.2.2 and JDK1.3-RC2
      (using WinNT 4.0).

      import javax.swing.*;
      import javax.swing.table.*;
      import javax.swing.event.TableModelListener;

      /**
       * A class containing TAB_COUNT tabs on a JTabbedPane. Each tab contains a
       * JScrollPane with a JTable. On the tables, we want to show a various amount
       * of rows.
       */
      class TestFrame extends JFrame implements TableModel {
          
          private final static int TAB_COUNT = 4;
          private final static int MAX_ROW_COUNT = 20;
          private final static int COLUMN_COUNT = 3;
          private static String[][][] tableContents = new String[TAB_COUNT][][];
          private JTabbedPane tabbedPane = new JTabbedPane();
          private JScrollPane scrollPane[] = new JScrollPane[TAB_COUNT];
          private JTable table[] = new JTable[TAB_COUNT];
          private int currentTab = 0;
          
          public static void main(String args[]) {
              new TestFrame("TestFrame");
          }
          
          public TestFrame(String name) {
              
              super(name);
      // Remove this row if using JDK1.2
              setDefaultCloseOperation(EXIT_ON_CLOSE);

              // Create a 3-d String array containing values for each cell in each
              // row of each table on each tab...
              for (int i=0; i<TAB_COUNT; i++) {
                  tableContents[i] = new String[MAX_ROW_COUNT][];
                  for (int j=0; j<MAX_ROW_COUNT; j++) {
                      tableContents[i][j] = new String[COLUMN_COUNT];
                      for (int k=0; k<COLUMN_COUNT; k++) {
                          tableContents[i][j][k] = String.valueOf(i+j+k);
                      }
                  }
              }
              
              // Create a scrollPane for each tab and a table for each scrollPane
              for (int i=0; i<TAB_COUNT; i++) {
                  table[i] = new JTable(this);
                  scrollPane[i] = new JScrollPane();
                  scrollPane[i].getViewport().add(table[i]);
                  tabbedPane.addTab(String.valueOf(i), scrollPane[i]);
              }
              
              getContentPane().add(tabbedPane);
              setBounds(100, 100, 300, 300);
              setVisible(true);
          }
          
          /*
           * Methods for implementing TableModel interface
           */
          
          public int getColumnCount() {
              return COLUMN_COUNT;
          }
          
          public int getRowCount() {
              int rowCount = 1 + tabbedPane.getSelectedIndex() * 3;
              rowCount = (rowCount > MAX_ROW_COUNT) ? MAX_ROW_COUNT : rowCount;
              System.out.println("RowCount: " + rowCount);
              return rowCount;
          }
          
          public Object getValueAt(int row, int column) {
              System.out.println("getValueAt: Row = " + row);
              return tableContents[tabbedPane.getSelectedIndex()][row][column];
          }
          public void addTableModelListener(TableModelListener l) {}
          public Class getColumnClass(int columnIndex) {return ((String)new
      String()).getClass();}
          public String getColumnName(int columnIndex) {return "Test";}
          public boolean isCellEditable(int rowIndex, int columnIndex) {return true;}
          public void removeTableModelListener(TableModelListener l) {}
          public void setValueAt(Object aValue, int rowIndex, int columnIndex) {}
      }
      (Review ID: 103816)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            stompkinsunw Sean Tompkins (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: