How can we double the height of JTable column header
we use following to createTable. I need to increase the height of column header .?
private JTable createTable()
{
return new JTable(dataTableModel)
{
protected JTableHeader createDefaultTableHeader()
{
return new JTableHeader(columnModel)
{
public String getToolTipText(MouseEvent event)
{
return " test";
};
}
};
# 1
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
public class TableHeaderTest {
public static void main(String[] args) {
JPanel panel = new JPanel(new GridLayout(0,2,5,0));
panel.add(new JScrollPane(getTable()));
JTable table = getTable();
Dimension d = table.getTableHeader().getPreferredSize();
d.height = 40;
table.getTableHeader().setPreferredSize(d);
panel.add(new JScrollPane(table));
JOptionPane.showMessageDialog(null, panel, "", -1);
}
private static JTable getTable() {
String[] colIds = { "Column 1", "Column 2" };
Object[][] data = new Object[2][2];
for(int j = 0; j < data.length; j++) {
for(int k = 0; k < data[j].length; k++) {
data[j][k] = "item " + (j*data[j].length + k+1);
}
}
JTable table =new JTable(data, colIds);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
return table;
}
}
# 5
[nobr]By default the height to the table header is set to the height ot the first cell in the header. So if you are going to use HTML then all you need to do is:
String[] colIds = { "<html>Column 1<br> </html>", "<html>Column 2<br>hello world" };
[/nobr]