JTable header question.

I have the following code:

--

MyTableModel mtm = new MyTableModel();

String[] columnNames = {

"Date ",

"Item \n Description ", // <-- This line!!!

"Amount "};

// clear all rows

mtm.setRowCount(0);

mtm.setColumnIdentifiers(columnNames);

--

I would like to display header in two lines.

I added "\n" in to header string..........

I guess it doesn't work that way.

How do I show header in two lines?

Thank you.

[507 byte] By [tsongweia] at [2007-10-2 10:22:59]
# 1
To get two line headers you need to use HTML. i.e.:<html><center>ItemDescription</center></html>
mjparmea at 2007-7-13 1:55:29 > top of Java-index,Desktop,Core GUI APIs...
# 2
I can't find any specific example about this.Does anyone know where can I get some sample code?
tsongweia at 2007-7-13 1:55:29 > top of Java-index,Desktop,Core GUI APIs...
# 3

> Does anyone know where can I get some sample code?

You where given sample code.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.

camickra at 2007-7-13 1:55:29 > top of Java-index,Desktop,Core GUI APIs...
# 4
Sorry for not being clear.The text for my table header is too long, so I need to display it in 2 lines.Instead of "Item Description"I need to show"Item"on the first line of header."Description" on the second line of header.Thanks
tsongweia at 2007-7-13 1:55:29 > top of Java-index,Desktop,Core GUI APIs...
# 5

[nobr]hello,

hope this help

import javax.swing.JFrame;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.table.DefaultTableModel;

public class table extends JFrame{

public TestDateFormate(){

JTabletable;

JScrollPanetableView;

DefaultTableModeltableModel;

Vector header = new Vector();

Vector data= new Vector();

header.addElement("<html>Item<br>Description</html>");

header.addElement("Reserves");

header.addElement("Amount");

header.addElement("ID");

header.addElement("ReservesRefID");

tableModel = new DefaultTableModel(data, header);

table= new JTable(tableModel);

tableView= new JScrollPane(table);

table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

table.getTableHeader().setReorderingAllowed(false);

getContentPane().add(tableView);

setVisible(true);

pack();

}

public static void main(String args[]){

new table();

}

}

[/nobr]

dayanandabva at 2007-7-13 1:55:29 > top of Java-index,Desktop,Core GUI APIs...
# 6
> The text for my table header is too long, so I need to display it in 2 lines.Yes, and you where given the solution for that exact question.
camickra at 2007-7-13 1:55:29 > top of Java-index,Desktop,Core GUI APIs...