wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes how to get column header click event on a JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to get column header click event on a JTable" Watch "how to get column header click event on a JTable" New topic
Author

how to get column header click event on a JTable

SLAZ IN
Greenhorn

Joined: Oct 13, 2005
Posts: 2
Hi,
I am a beginner to JAVA. I have created a Jtable and added it to a JScrollpane. It is having 6 column headers.

I want to sort the contents of the table when we click on the column header.For that i want to know the event which is occurred on click.How can I know that on which column header the click is happened? What is the event that occurs on click on the column header?

The code written for creating the table is given below.

JTable mainTable = new JTable();
JScrollPane mainTableScrlPane = new JScrollPane();

DefaultTableModel mainTableModel = (new DefaultTableModel(new
Object [][] {}, new String [] {"Name","ID","Date","Time","Status","Physician"})
{
boolean[] canEdit = new boolean[]{false,false,false,false};
public boolean isCellEditable(int rowIndex,int colIndex)
{
return canEdit[colIndex];
}});

mainTable.setModel(mainTableModel);
mainTableScrlPane.getViewport().add(mainTable, null);

Please help me...
tito bayuadji
Greenhorn

Joined: Apr 18, 2002
Posts: 12
hi,

IMHO you can get table header component using
JTable.getTableHeader

then add a mouse click to that component.

good luck
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get column header click event on a JTable