• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

how to get column header click event on a JTable

Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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];

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

Please help me...
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

IMHO you can get table header component using

then add a mouse click to that component.

good luck
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
    Bookmark Topic Watch Topic
  • New Topic