-
Bug
-
Resolution: Won't Fix
-
P4
-
1.3.1, 1.4.1, 1.4.2
-
x86
-
windows_2000, windows_xp
Name: jk109818 Date: 08/18/2003
FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
When instantiating a JList and calling its setPreferredSize method, then placing it into a JScrollPane, it does not redraw anthing that is not in the viewport of the JScrollPane.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the following program and look at the row headers as you scroll. Then comment out the setPreferredSize method.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Redrawing should be normal but isn't.
ACTUAL -
The column is not redrawn properly.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
/**
* @version 1.0 11/09/98
*/
class RowHeaderRenderer extends JLabel implements ListCellRenderer {
RowHeaderRenderer(JTable table) {
JTableHeader header = table.getTableHeader();
setOpaque(true);
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
setHorizontalAlignment(CENTER);
setForeground(header.getForeground());
setBackground(header.getBackground());
setFont(header.getFont());
}
public Component getListCellRendererComponent( JList list,
Object value, int index, boolean isSelected, boolean cellHasFocus) {
setText((value == null) ? "" : value.toString());
return this;
}
}
public class RowHeaderExample extends JFrame {
public RowHeaderExample() {
super( "Row Header Example" );
setSize( 300, 150 );
ListModel lm = new AbstractListModel() {
String headers[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i"};
public int getSize() { return headers.length; }
public Object getElementAt(int index) {
return headers[index];
}
};
DefaultTableModel dm = new DefaultTableModel(lm.getSize(),10);
JTable table = new JTable( dm );
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JList rowHeader = new JList(lm);
rowHeader.setFixedCellWidth(50);
// rowHeader.setPreferredSize(new Dimension(50, 30));
rowHeader.setFixedCellHeight(table.getRowHeight()
+ table.getRowMargin());
// + table.getIntercellSpacing().height);
rowHeader.setCellRenderer(new RowHeaderRenderer(table));
JScrollPane scroll = new JScrollPane( table );
scroll.setRowHeaderView(rowHeader);
getContentPane().add(scroll, BorderLayout.CENTER);
}
public static void main(String[] args) {
RowHeaderExample frame = new RowHeaderExample();
frame.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit(0);
}
});
frame.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Don't try to call this but if you don't you're faced with a column that does not allow for any margin space around the textual content within which looks horrible. The other alternative is to use a fixed size. Both alternatives do not support a realistic expectation when attempting to create a spreadsheet like program.
(Incident Review ID: 199352)
======================================================================
FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
When instantiating a JList and calling its setPreferredSize method, then placing it into a JScrollPane, it does not redraw anthing that is not in the viewport of the JScrollPane.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the following program and look at the row headers as you scroll. Then comment out the setPreferredSize method.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Redrawing should be normal but isn't.
ACTUAL -
The column is not redrawn properly.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
/**
* @version 1.0 11/09/98
*/
class RowHeaderRenderer extends JLabel implements ListCellRenderer {
RowHeaderRenderer(JTable table) {
JTableHeader header = table.getTableHeader();
setOpaque(true);
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
setHorizontalAlignment(CENTER);
setForeground(header.getForeground());
setBackground(header.getBackground());
setFont(header.getFont());
}
public Component getListCellRendererComponent( JList list,
Object value, int index, boolean isSelected, boolean cellHasFocus) {
setText((value == null) ? "" : value.toString());
return this;
}
}
public class RowHeaderExample extends JFrame {
public RowHeaderExample() {
super( "Row Header Example" );
setSize( 300, 150 );
ListModel lm = new AbstractListModel() {
String headers[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i"};
public int getSize() { return headers.length; }
public Object getElementAt(int index) {
return headers[index];
}
};
DefaultTableModel dm = new DefaultTableModel(lm.getSize(),10);
JTable table = new JTable( dm );
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JList rowHeader = new JList(lm);
rowHeader.setFixedCellWidth(50);
// rowHeader.setPreferredSize(new Dimension(50, 30));
rowHeader.setFixedCellHeight(table.getRowHeight()
+ table.getRowMargin());
// + table.getIntercellSpacing().height);
rowHeader.setCellRenderer(new RowHeaderRenderer(table));
JScrollPane scroll = new JScrollPane( table );
scroll.setRowHeaderView(rowHeader);
getContentPane().add(scroll, BorderLayout.CENTER);
}
public static void main(String[] args) {
RowHeaderExample frame = new RowHeaderExample();
frame.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit(0);
}
});
frame.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Don't try to call this but if you don't you're faced with a column that does not allow for any margin space around the textual content within which looks horrible. The other alternative is to use a fixed size. Both alternatives do not support a realistic expectation when attempting to create a spreadsheet like program.
(Incident Review ID: 199352)
======================================================================