KidsLovePC Contact Us
  Home   PHP  Graphics ASP  JavaScript   J2EE  HTML  JAVA   Swing   Webtip  Forums  Lyric  Free sheet music  Ringtones
java,jtable,jtree,swing Return to JAVA table list

Best books about JAVA programming:

JAVA JTable Sorting column

The following code demos how to sort multiple columns in JTable. This example includes two files: and

//All copyright reserved by
//No redistribution is allowed without author permission and a back link to
// Example from
// is not responsible for your data loss or any damage.

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.table.*;
import javax.swing.*;
import java.awt.Color ;
import java.awt.Component;

public class SorterDemo extends JPanel {

public SorterDemo() {
super(new GridLayout(1,0));

String[] columnNames = {"First Name",
"Last Name",

Object[][] data = {
{"Hugo", "Jone",
"JAVA for dummy"},
{"Harry", "Potter",
"JAVA cook book Seconde Edtion"},
{"Tom", "Sawyer",
" is cool"},
{"Alice", "Wonder",
"JAVA JTABLE is all in"},
{"Bill", "Bush",
"JAVA world"}

DefaultTableModel dtm=new DefaultTableModel(data,columnNames);
//how use table sorter
TableSorter tableSorter= new TableSorter (dtm);
JTable table = new JTable(tableSorter);
tableSorter.setSortingStatus(0,1); //pre-set sorting on first column;
table.setPreferredScrollableViewportSize(new Dimension(500, 70));

//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.

//Create and set up the window.
JFrame frame = new JFrame("Table Sorter Demo");

//Create and set up the content pane.
SorterDemo newContentPane = new SorterDemo();
newContentPane.setOpaque(true); //content panes must be opaque

//Display the window.


Sponsored link
Java JTabbedPane
JTabbedPane Preview List
Java JComboBox
JComboBox Preview List
Java JTooltip
JTooltip Preview List
Java JList
JList Preview List
Java JTree
JTree Preview List 1
JTree Preview List 2
JTable Preview List 1
JTable Preview List 2
JTable Preview List 3
JTable Preview List 4
JTable Preview List 5
JTable Preview List 6
JTable Preview List 7
JAVA Jslide
JSlide Preview List



Best books about JAVA programming from Amazon
Professional Java, JDK 5 Edition (Paperback Simply Java Programming: An Application-Driven Tutorial Approach (Paperback) Effective Java Programming Language Guide (Paperback) Head First Java, 2nd Edition (Paperback) Java : An Introduction to Problem Solving and Programming (4th Edition)


Printer Inkjet A Z lyricsLearn ChineseHome|PHP|Swing|HTML|JavaScript|ASP|JAVA|Forum|WebTip|Contact Us
Copyright © All rights reserved(new). Privacy|Copyright
designed by

Please help us cover the web site maintenance fee.
barcode scanner Thermal Printer credit card machine bar code printer