JDK-6389065 : REGRESSION: JTableHeader's default alignment changed.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0u2,6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-02-22
  • Updated: 2010-04-03
  • Resolved: 2006-03-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b76Fixed
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE REGRESSION :
JDK: Mustang b72
OS:Windows XP Professional SP1+
L&F: Windows XP L&F
JTable's default header text alignment is center alignment on Mustang while it was left alignment on J2SE 5.0

REPRODUCIBLE TESTCASE OR STEPS TO REPRODUCE:
package testbug;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.TableColumn;

public class TestTableHeader extends JFrame{
    private JScrollPane jScrollPane1 = new JScrollPane();

    private String[] columnNames = {"First Name",
                            "Last Name",
                            "Sport",
                            "# of Years",
                            "Vegetarian"};

    private Object[][] data = {
        {"Mary", "Campione",
         "Snowboarding", new Integer(5), new Boolean(false)},
        {"Alison", "Huml",
         "Rowing", new Integer(3), new Boolean(true)},
        {"Kathy", "Walrath",
         "Knitting", new Integer(2), new Boolean(false)},
        {"Sharon", "Zakhour",
         "Speed reading", new Integer(20), new Boolean(true)},
        {"Philip", "Milne",
         "Pool", new Integer(10), new Boolean(false)}
    };


    private JTable jTable1 = new JTable(data, columnNames);
        
    public TestTableHeader() {
        try {
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        jScrollPane1.getViewport().add(jTable1, null);
        this.getContentPane().add(jScrollPane1, null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        TableColumn column = null;
        for (int i = 0; i < 5; i++) {
            column = jTable1.getColumnModel().getColumn(i);
            if (i == 2) {
                column.setPreferredWidth(1700); //sport column is bigger
            } else {
                column.setPreferredWidth(500);
            }
        }
        jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    }
    
    public static void main(String[] argv){
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            TestTableHeader tbl = new TestTableHeader();
            tbl.setVisible(true);
        } catch (Exception e) {
        }

    }
}


RELEASE LAST WORKED:
5.0 Update 6

RELEASE TEST FAILS:
mustang-beta

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Left Alignment Please
ACTUAL -
Center Allignment

Comments
EVALUATION Shannon's evaluation is spot on. The fix will be to specify a leading alignment in the windows header renderer.
23-02-2006

EVALUATION This was introduced by 4747079. The superclass of WindowsTableHeaderUI.XPDefaultRenderer was changed to something that is shared with Metal and the other look and feels. This superclass center-aligns. Previously the Windows renderer subclassed directly from DefaultTableCellRenderer, which left-aligns. Left alignment is a better match for XP.
22-02-2006