JDK-4523678 : Shared TableColumnModel resizing is faulty.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2001-11-06
  • Updated: 2024-06-10
  • Resolved: 2024-06-10
Related Reports
Relates :  
Description
I have reproduced this bug on merlin-beta3.

###@###.### 2001-12-20


Name: jk109818			Date: 11/06/2001


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


/**
 * When a TableColumnModel is shared and the second table
 * is not in a scrollpane, the column resizing, using the
 * mouse, is screwy - the columns doesn't follow the mouse.
 *
 * Both In ScrollPane, shared model = OK
 * Both In ScrollPane, unshared model = OK
 * One Not In ScrollPane, shared model = PROBLEM
 * One Not In ScrollPane, unshared model = OK
 *
 * This is a problem for me as I want one table vertically
 * scrollable, and another table to sit below it, always
 * visible, resizing with it. (The bottom table would hold
 * column totals)
 *
 * Voters for this may also care to vote for
 * <A
HREF="http://developer.java.sun.com/developer/bugParade/bugs/4498704.html">
 * 4498704</A> another bug to do with Table Columns.
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;

public class TableDemo2 extends JPanel {

    private JCheckBox checkColumnModel =
            new JCheckBox("Share TableColumnModel");

    private JCheckBox checkScrollPane =
            new JCheckBox("Put second Table in a scrollpane");

    public TableDemo2() {
        super( new GridLayout(4,1) );
        final JTable table1 = new JTable( new DemoTableModel() );
        final JTable table2 = new JTable( new TotalTableModel() );
        final TableColumnModel table2originalColumnModel =
                table2.getColumnModel();

        final JScrollPane scrollPane = new JScrollPane();

        checkColumnModel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                table2.setColumnModel(checkColumnModel.isSelected()
                        ? table1.getColumnModel()
                        : table2originalColumnModel );
            }
        });

        checkScrollPane.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (checkScrollPane.isSelected()) {
                    TableDemo2.this.remove(table2);
                    scrollPane.setViewportView(table2);
                    TableDemo2.this.add(scrollPane);
                } else {
                    TableDemo2.this.remove(scrollPane);
                    TableDemo2.this.add(table2);
                }
                TableDemo2.this.repaint();
            }
        });

        this.add(checkColumnModel);
        this.add(checkScrollPane);
        this.add(new JScrollPane(table1));
        this.add(table2);
    }

    private class DemoTableModel extends AbstractTableModel {
        public int getRowCount() {
            return 2;
        }
        public int getColumnCount() {
            return 5;
        }
        public String getColumnName(int col) {
            return "DEMO";
        }
        public Object getValueAt(int row, int col) {
            return new Double(col);
        }
    }
    private class TotalTableModel extends AbstractTableModel {
        public int getRowCount() {
            return 1;
        }
        public int getColumnCount() {
            return 5;
        }
        public Object getValueAt(int row, int col) {
            return new Double(2*col);
        }
    }

    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.getContentPane().add(new TableDemo2());
        f.pack();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
    }
}
(Review ID: 135076) 
======================================================================

Comments
WORK AROUND Name: jk109818 Date: 11/06/2001 Haven't tried yet, but shall try putting the second table in a scrollpane, and the replacing the column header component after it is automatically place in the top of the scrollpane. ======================================================================
25-09-2004

EVALUATION Should investigate 4816146 with this bug. They may be related. ###@###.### 2003-07-08
08-07-2003