JDK-4899334 : Strings starting with 'W' are truncated in table cells
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-07-31
  • Updated: 2003-09-26
  • Resolved: 2003-09-26
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.
Other
5.0 tigerFixed
Related Reports
Relates :  
Description

Name: rmT116609			Date: 07/31/2003


FULL PRODUCT VERSION :
ava version "1.4.2"
ava(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
ava HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
in table cells the Strings starting with 'W' are truncated when using a specific Cell Renderer

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
just run the code under 1.4.2

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected String 'Wine'
ACTUAL -
Got 'Wi...'

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.util.*;

public class TableTest extends javax.swing.JFrame {
    
    /** Creates new form TableTest */
    public TableTest() {
        jTable1 = new JTable();
        
        
        DefaultTableModel def= new DefaultTableModel(
            new Object [][] {
                {"Fine", "Wine"}
            },
            new String [] {
                "OK", "Truncated"
            }
        );
        jTable1.setModel(def);

        getContentPane().removeAll();
        JScrollPane jp = new JScrollPane(jTable1);
        getContentPane().add(jp);
        TableModel dtb = jTable1.getModel();
        ColorCellRenderer cctl = new ColorCellRenderer();

        for (int i =0; i<dtb.getColumnCount();i++) {
            jTable1.setDefaultRenderer(jTable1.getColumnClass(i),
            cctl);
        }
        pack();
    }
    
        
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new TableTest().show();
    }
    
    
    // Variables declaration - do not modify
    private javax.swing.JTable jTable1;
    // End of variables declaration
    
}



class ColorCellRenderer extends JPanel implements TableCellRenderer {
        private JLabel label;
        
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col)
        {
            String text="";
            if (value!=null)
                text = value.toString();
            label.setText(text);
           
            return this;
        }

        public ColorCellRenderer()
        {
            label = new JLabel();
            label.setHorizontalTextPosition(JLabel.LEFT);
            setLayout(new BorderLayout());
            add(label, BorderLayout.WEST);
        }
        

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Modify the last line to
add(label, BorderLayout.CENTER);
(Incident Review ID: 193226) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b22
14-06-2004

EVALUATION This is a result of the fix for 4716362. The code is such that we'll end up checking if the text is too small based on the string width - lsb, where as we'll return string width, so that if the widget gets the size it requested the text will be clipped. The easiest solution, which is far from ideal, appears to pad the width by the -lsb, in effect giving more space than is needed. The advantage of this approach is that preferred size will now be big enough for the text and callers can do a drawString on the returned location. ###@###.### 2003-09-15
15-09-2003