mhm also dass mit dem Sorter klappt nicht so wirklich!!
Es sind alle Daten als String gespeichert....Nun wollte ich folgender maßen meine Double Werte Sortieren
Code:
//in der Table
getTableHeader().addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
setRowSorter(sorter);
if(update)
{
JTableHeader header = (JTableHeader) evt.getSource();
int column = header.getColumnModel().getColumnIndexAtX(evt.getX());
getTabellenModel().setSortedCol(column);
for(int i=0;i<tModel.getRowCount();i++)
{
try
{
Long.parseLong(tModel.getValueAt(i,column).toString());
getTabellenModel().setTypes("STRING");
}
catch (Exception e)
{
try
{
Double.parseDouble(tModel.getValueAt(i,column).toString());
getTabellenModel().setTypes("DOUBLE");
}
catch (Exception e1)
{
getTabellenModel().setTypes("STRING");
break;
}
}
}
}
else
{
update=true;
}
}
Code:
//im model
public void setTypes(String type)
{
sTypes=type;
}
private int getSortedCol()
{
return sortedCol;
}
public void setSortedCol(int sortedColumn)
{
sortedCol=sortedColumn;
}
private String getTypes()
{
return sTypes;
}
public Class getColumnClass(final int columnIndex)
{
if(getSortedCol()==columnIndex)
{
if(getTypes().equals("DOUBLE"))
{
return types [1];
}
if(getTypes().equals("STRING"))
{
return types [2];
}
}
return types [2];
}
bekomme immer diese Exception
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Cannot format given Object as a Number
at java.text.DecimalFormat.format(Unknown Source)
at java.text.Format.format(Unknown Source)
at org.jdesktop.swing.JXTable$DoubleRenderer.setValue(Unknown Source)
at javax.swing.table.DefaultTableCellRenderer.getTableCellRendererComponent(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at org.jdesktop.swing.JXTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown 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(Unknown 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(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)