aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Icon needed in JTableHeader for Sorting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Icon needed in JTableHeader for Sorting" Watch "Icon needed in JTableHeader for Sorting" New topic
Author

Icon needed in JTableHeader for Sorting

Rohit Kedia
Ranch Hand

Joined: Apr 24, 2010
Posts: 79
Hi ,
I needed to sort my JTable selective columns based on the columns which I click.
I was able to successfully implement that using this link form java2s site Java2s

Now i needed is that whenever I sort the Table by clicking on any of the TableHeader an Icon should show in the Header like arrow up or down for ascending or descending order.

I also have a problem here which is I am using the column Names as <HTML><B>column Name</B></HTML> as I have to show some column Names in bold.

Please help me
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

Throw away all you've done and start using TableRowSorter. Just instantiate one, call table.setRowSorter and you'll get all of that for free!
Disclaimer: available since Java 6


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rohit Kedia
Ranch Hand

Joined: Apr 24, 2010
Posts: 79
Rob Prime wrote:Throw away all you've done and start using TableRowSorter. Just instantiate one, call table.setRowSorter and you'll get all of that for free!
Disclaimer: available since Java 6


Sir I wanted to know that can I sort some specific columns and not all the columns. I had used Rowsorter but the Issue was that
for Example :
Suppose I have 12 columns in my JTable I want to sort the Row data based on only 6 columns can this be done using Rowsorter.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2203
    
    7
I want to sort the Row data based on only 6 columns can this be done using Rowsorter.


A JTable actually uses the DefaultRowSorter and yes this can be done using this class.
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
Does nobody look into the Swing tutorials and/or the API docs anymore?
-> http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#sorting
-> http://java.sun.com/javase/7/docs/api/javax/swing/DefaultRowSorter.html#setSortable(int, boolean)


Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
Rohit Kedia
Ranch Hand

Joined: Apr 24, 2010
Posts: 79
Getting this Error





Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
Did you look at the examples? They all have something similar, that is missing in your code. Exactly. They use the TableRowSorter constructor providing an actual model (e.g. table.getModel()). I think that might be the problem here.
Rohit Kedia
Ranch Hand

Joined: Apr 24, 2010
Posts: 79
Yes that Issue is resolved but the problem still prevails which is it still sorting all the Columns I only want to sort on basis of certain specific columns.


there are 12 columns but I want to use only these column for sorting apart from that I was adding 10 blank rows at the end I do not want to include them in sorting but it is still coming.

Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
You did see the second link I provided (the link to the setSortable() method)? You can explicitely define which columns should be sortable (and which not). Please show some effort and at least pretend to read the provided docs/tutorials...
Rohit Kedia
Ranch Hand

Joined: Apr 24, 2010
Posts: 79
Peter Taucher wrote:You did see the second link I provided (the link to the setSortable() method)? You can explicitely define which columns should be sortable (and which not). Please show some effort and at least pretend to read the provided docs/tutorials...


I am really very sorry for this... actually I was bit tensed... so skipped it...

anyways the Issue is resolved thanks for the Effort... and help...
Rajesh k Jha
Ranch Hand

Joined: May 10, 2009
Posts: 72
I am also having similar issue,
I want sorting to be applied only to some selected column, but Rohit has not posted the way he has solved his issue, At least he should have realized to post the answer so that other can get benefit of it.

I am still trying to find the answer of this problem,
Any further help is appreciated.
David Byron
Rancher

Joined: Jan 20, 2009
Posts: 172

Rajesh k Jha wrote:I am also having similar issue,
I want sorting to be applied only to some selected column... I am still trying to find the answer of this problem...

Have you looked here?


SCJD 6, OCPJP7, Baroque Potion, G+
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Icon needed in JTableHeader for Sorting