Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JTable Sorting 1

Status
Not open for further replies.

Miros

Programmer
Jan 27, 2001
506
0
0
US
Could someone point me to some sample code which allows to user to sort a JTable?
 
Thanks much! Looking at all the methods for the Sorter class, I just couldn't tell which ones I really needed.
 
Ahh ... the joys of a good google :)

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Next horrid question...

These are my imports, which are the same ones in the sample program, plus a few for other uses:
import java.awt.event.* ;
import java.awt.* ;
import javax.swing.* ;
import javax.swing.table.* ;
import java.io.* ;
import java.net.* ;
import java.util.regex.* ;
import javax.swing.table.AbstractTableModel ;

I still get an error at compile time:
"cannot find symbol class TableSorter"

This is where I got stuck before, and assumed I was doing something fundamentally wrong. Since I now know it's fundamentally right, I'm completely confused!

I have terrible luck with finding code samples using Google... no idea why, or I'd do things a little differently and actually _find_ what I want!
 
Here's the full text of my error messages:

f:\Xinox Software\JCreatorV3LE\MyProjects\TSRAutomation\src\TSRTablePanel.java:21: cannot find symbol
symbol : class TableSorter
location: class TSRTablePanel
TableSorter sorter = new TableSorter(new TSRTableModel());
^
f:\Xinox Software\JCreatorV3LE\MyProjects\TSRAutomation\src\TSRTablePanel.java:21: cannot find symbol
symbol : class TableSorter
location: class TSRTablePanel
TableSorter sorter = new TableSorter(new TSRTableModel());
^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

Process completed.
 
I have pasted together brute force a list of imports from all the sorting programs on that page.

import java.awt.event.* ;
import java.awt.* ;
import javax.swing.* ;
import javax.swing.table.* ;
import java.io.* ;
import java.net.* ;
import java.util.regex.* ;
import javax.swing.table.AbstractTableModel ;
import javax.swing.table.TableModel ;
import javax.swing.table.* ;

// try 1
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;

import javax.swing.*;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.*;

// try 2
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import java.awt.Dimension;
import java.awt.GridLayout;

// try 3
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;

import javax.swing.*;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.*;

// try 4
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
import javax.swing.event.TableModelListener;
import javax.swing.event.TableModelEvent;


I still get the same errors!

--------------------Configuration: TSRAutomation - JDK version <Default> - <Default>--------------------
Command : "F:\Sun\AppServer\jdk\bin\javac.exe" -classpath "f:\Xinox Software\JCreatorV3LE\MyProjects\TSRAutomation\classes\;F:\Sun\AppServer\jdk\jre\lib\rt.jar;F:\Sun\AppServer\jdk\lib\dt.jar;F:\Sun\AppServer\jdk\lib\tools.jar;F:\Sun\AppServer\jdk\jre\lib\ext\dnsns.jar;F:\Sun\AppServer\jdk\jre\lib\ext\localedata.jar;F:\Sun\AppServer\jdk\jre\lib\ext\sunjce_provider.jar;F:\Sun\AppServer\jdk\jre\lib\ext\sunpkcs11.jar" -d "f:\Xinox Software\JCreatorV3LE\MyProjects\TSRAutomation\classes" "f:\Xinox
Software\JCreatorV3LE\MyProjects\TSRAutomation\src\TSRTablePanel.java" -Xlint:deprecation
Directory : "f:\Xinox Software\JCreatorV3LE\MyProjects\TSRAutomation\src"

f:\Xinox Software\JCreatorV3LE\MyProjects\TSRAutomation\src\TSRTablePanel.java:58: cannot find symbol
symbol : class TableSorter
location: class TSRTablePanel
TableSorter sorter = new TableSorter(new TSRTableModel());
^
f:\Xinox Software\JCreatorV3LE\MyProjects\TSRAutomation\src\TSRTablePanel.java:58: cannot find symbol
symbol : class TableSorter
location: class TSRTablePanel
TableSorter sorter = new TableSorter(new TSRTableModel());
^
2 errors

Process completed.
 
Looks like a package error I would think.

You need to put the TableSorter class downloaded from the link into the same package as your code, and any other classes required from that link.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top