-
Bug
-
Resolution: Not an Issue
-
P1
-
None
-
1.4.0
-
sparc
-
solaris_8
See the following codes:
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.awt.event.*;
public class TestJTblSize extends JFrame
{
public TestJTblSize() {
Object[][] data = {
{"Mark", "Andrews", "red", "Baseball", "1"},
{"Tom", "Ball", "Blue", "Football", "2"},
{"Alan", "Chung", "Green", "Baseball", "3"},
{"Jeff", "Dinkins", "Turquois", "Football", "4"},
{"Amy", "Fowler", "Yellow", "Hockey", "5"}
};
String[] headers = {"col1", "col2", "col3", "col4", "col5"};
MyTable table = new MyTable(data, headers);
JScrollPane scrollPane = new JScrollPane(table);
Container c = getContentPane();
c.setLayout(new BorderLayout());
c.add(scrollPane, BorderLayout.CENTER);
}
static public void main(String[] args) {
TestJTblSize spTest = new TestJTblSize();
spTest.pack();
spTest.setVisible(true);
}
}
class MyTable extends JTable {
public MyTable(Object[][] data, Object[] columnNames) {
super(data, columnNames);
setBorder(new LineBorder(Color.black, 1));
}
public Dimension getPreferredSize() {
Dimension dim = super.getPreferredSize();
dim.height = (getRowHeight() + getRowMargin()) * getRowCount();
return dim;
}
}
after compile and run it under 1.2 and 1.4, you will find under jdk1.2, table's height is composed of rows height and rows margins, but under jdk1.4, table's height is composed of only rows height. it makes a product can not work both on jdk1.2 and jdk1.4.
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.awt.event.*;
public class TestJTblSize extends JFrame
{
public TestJTblSize() {
Object[][] data = {
{"Mark", "Andrews", "red", "Baseball", "1"},
{"Tom", "Ball", "Blue", "Football", "2"},
{"Alan", "Chung", "Green", "Baseball", "3"},
{"Jeff", "Dinkins", "Turquois", "Football", "4"},
{"Amy", "Fowler", "Yellow", "Hockey", "5"}
};
String[] headers = {"col1", "col2", "col3", "col4", "col5"};
MyTable table = new MyTable(data, headers);
JScrollPane scrollPane = new JScrollPane(table);
Container c = getContentPane();
c.setLayout(new BorderLayout());
c.add(scrollPane, BorderLayout.CENTER);
}
static public void main(String[] args) {
TestJTblSize spTest = new TestJTblSize();
spTest.pack();
spTest.setVisible(true);
}
}
class MyTable extends JTable {
public MyTable(Object[][] data, Object[] columnNames) {
super(data, columnNames);
setBorder(new LineBorder(Color.black, 1));
}
public Dimension getPreferredSize() {
Dimension dim = super.getPreferredSize();
dim.height = (getRowHeight() + getRowMargin()) * getRowCount();
return dim;
}
}
after compile and run it under 1.2 and 1.4, you will find under jdk1.2, table's height is composed of rows height and rows margins, but under jdk1.4, table's height is composed of only rows height. it makes a product can not work both on jdk1.2 and jdk1.4.