Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Jtable: How to sort by columns and change the color of rows and columns

Posted on 2003-12-05
5
Medium Priority
?
318 Views
Last Modified: 2012-05-04
Hi, this is a quick question, I'm using a jtable and need to know how to sort by columns and change the color of rows and columns. I've been told that there is a propperty but I cannot find it.
Thanx in advance for your help.

Ron.
0
Comment
Question by:rvaldivia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 9883400
These are really two quite separate questions

a. you need to sort the TableModel
b. you need to set the cell renderer appropriately
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9883413
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9883444
a. Something like

class SortableDefaultTableModel extends DefaultTableModel implements Comparator {

      private int sortColumn;

      public void sortByColumn(int sortColumn){
            this.sortColumn = sortColumn;
            //System.out.println("Sorting on column " + sortColumn);
            Collections.sort(dataVector, this);
      }

      public int compare(Object o1, Object o2){
            if (o1 == null) return -1;
            if (o2 == null) return 1;

            Vector vect1 = (Vector) o1;
            Vector vect2 = (Vector) o2;
            Comparable col1 = (Comparable) vect1.get(sortColumn);
            Comparable col2 = (Comparable) vect2.get(sortColumn);
            return col1.compareTo(col2);
      }
}
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question