Results 1 to 4 of 4
Thread: TableSorter
- 09-16-2008, 02:28 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 3
- Rep Power
- 0
TableSorter
Im using TableSorter.java available from java.sun.com/docs/books/tutorial/uiswing/examples/components/TableSorterDemoProject/src/components/TableSorter.java
to sort my table, which includes a column with dates. Heres what i tried
However when i modify my table in any way it comes up with a NullPointerException. If i just use the DefaultTableModel my code works fine except it compares everything as strings.Java Code:DefaultTableModel model = new DefaultTableModel() { Class [] classes = {int.class, String.class, String.class, Date.class, Date.class, double.class}; public Class getColumnClass(int column) { return classes[column]; } }; TableSorter sorter = new TableSorter(model); JTable table = new JTable(sorter); sorter.setTableHeader(table.getTableHeader());
How do i compare the table elements using the correct class?
- 09-16-2008, 03:49 PM #2
If you are getting an error, copy and paste the full text of the message here. The error message has the souce code line number in it. Copy and paste the code around that line here also.it comes up with a NullPointerException.
- 09-16-2008, 03:55 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 3
- Rep Power
- 0
No line number was given, if i replace
withJava Code:DefaultTableModel model = new DefaultTableModel() { Class [] classes = {int.class, String.class, String.class, Date.class, Date.class, double.class}; public Class getColumnClass(int column) { return classes[column]; } };
The program works fine. Here is the exception.Java Code:DefaultTableModel model =new DefaultTableModel();
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unkn own Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unk nown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unkno wn Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Un known Source)
at javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
- 09-16-2008, 10:48 PM #4


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks