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";

};

}

};

[410 byte] By [screen_simua] at [2007-11-27 7:04:36]
# 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;

}

}

crwooda at 2007-7-12 18:55:55 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thank you for the information , it really helps. One more question I had was how can we wrap the text specified in column header?
screen_simua at 2007-7-12 18:55:55 > top of Java-index,Desktop,Core GUI APIs...
# 3
[nobr]String[] colIds = { "Column 1", "<html>Column 2<br>hello world" };[/nobr]
crwooda at 2007-7-12 18:55:55 > top of Java-index,Desktop,Core GUI APIs...
# 4
Thanks much for you help.
screen_simua at 2007-7-12 18:55:55 > top of Java-index,Desktop,Core GUI APIs...
# 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]

camickra at 2007-7-12 18:55:55 > top of Java-index,Desktop,Core GUI APIs...