Habe viel ausprobiert und bin langsam frustriert! Es wird einfach nicht initial sortiert:
Java:
package einsatz;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.RowSorter;
import javax.swing.SortOrder;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class TriBsp extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
public TriBsp() {
String rowData[][] = { { "x-MAN", "3860", "0,8762", "0,153", "198", "Ironman-Langdistanz (DTU Langdistanz)" },
{ "x-MAN", "1900", "0,7858", "0,1446", "195", "Ironman-Half" },
{ "LM", "1500", "0,867", "0,1689", "99",
"DTU-Junioren-Triathlon lang (18-19) - DTU-Elite-Triathlon (18-19) - DTU-AK20++ kurz (20-99) - ITU-Kurzdistanz (olympische Distanz) - Jedermann" },
{ "LM", "750", "0,9109", "0,1845", "27",
"DTU-Jugend-Triathlon A (16-17) - DTU-Junioren-Triathlon kurz (18-19) - ITU-Sprintdistanz - Schnupper" },
{ "BL", "1500", "1,0593", "0,157", "50",
"DTU-Junioren-Triathlon lang (18-19) - DTU-Elite-Triathlon (18-19) - DTU-AK20++ kurz (20-99) - ITU-Kurzdistanz (olympische Distanz) - Jedermann" },
{ "BL", "750", "0,984", "0,2327", "38",
"DTU-Jugend-Triathlon A (16-17) - DTU-Junioren-Triathlon kurz (18-19) - ITU-Sprintdistanz - Schnupper" },
{ "BL", "400", "1,0057", "0,1889", "22",
"DTU-Schüler-Triathlon A (12-13) - DTU-Jugend-Triathlon B (14-15) - DTU Fitness" },
{ "BL", "200", "0,6951", "0,0855", "4", "DTU-Schüler-Triathlon B (10-11)" },
{ "BL", "100", "0,4266", "0,0741", "4", "DTU-Schüler-Triathlon C (8-9)" },
{ "BL/LL", "1500", "2,7244", "0,1614", "11",
"DTU-Junioren-Triathlon lang (18-19) - DTU-Elite-Triathlon (18-19) - DTU-AK20++ kurz (20-99) - ITU-Kurzdistanz (olympische Distanz) - Jedermann" },
{ "BL/LL", "750", "1,2424", "0,2117", "69",
"DTU-Jugend-Triathlon A (16-17) - DTU-Junioren-Triathlon kurz (18-19) - ITU-Sprintdistanz - Schnupper" },
{ "BL/LL", "400", "1,0225", "0,1637", "77",
"DTU-Schüler-Triathlon A (12-13) - DTU-Jugend-Triathlon B (14-15) - DTU Fitness" },
{ "BL/LL", "200", "0,5373", "0,0514", "40", "DTU-Schüler-Triathlon B (10-11)" },
{ "LL/KL/RL", "2000", "0,8676", "0,151", "755", "DTU-AK20++ mittel (20-99)" },
{ "LL/KL/RL", "1500", "0,8115", "0,172", "2079",
"DTU-Junioren-Triathlon lang (18-19) - DTU-Elite-Triathlon (18-19) - DTU-AK20++ kurz (20-99) - ITU-Kurzdistanz (olympische Distanz) - Jedermann" },
{ "LL/KL/RL", "750", "0,7209", "0,1731", "1672",
"DTU-Jugend-Triathlon A (16-17) - DTU-Junioren-Triathlon kurz (18-19) - ITU-Sprintdistanz - Schnupper" },
{ "LL/KL/RL", "400", "0,3002", "0,0455", "244",
"DTU-Schüler-Triathlon A (12-13) - DTU-Jugend-Triathlon B (14-15) - DTU Fitness" },
{ "LL/KL/RL", "200", "0,8977", "0,1992", "39", "DTU-Schüler-Triathlon B (10-11)" } };
String[] columnNames = { "Liga", "Strecke", "mue", "sigma", "n", "Bezeichnung bzw AK" };
DefaultTableModel model = new DefaultTableModel(rowData, columnNames);
JTable table = new JTable(model);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
table.setRowSelectionAllowed(true);
table.setColumnSelectionAllowed(false);
table.setAutoCreateRowSorter(true);
List <RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING));
final int INDEX_COLUMN1 = 0;
TableColumn col = table.getColumnModel().getColumn(INDEX_COLUMN1);
col.setPreferredWidth(75);
final int INDEX_COLUMN2 = 1;
TableColumn col2 = table.getColumnModel().getColumn(INDEX_COLUMN2);
col2.setPreferredWidth(50);
table.getColumnModel().getColumn(1).setCellRenderer(rightRenderer);
final int INDEX_COLUMN3 = 2;
TableColumn col3 = table.getColumnModel().getColumn(INDEX_COLUMN3);
col3.setPreferredWidth(45);
final int INDEX_COLUMN4 = 3;
TableColumn col4 = table.getColumnModel().getColumn(INDEX_COLUMN4);
col4.setPreferredWidth(45);
final int INDEX_COLUMN5 = 4;
TableColumn col5 = table.getColumnModel().getColumn(INDEX_COLUMN5);
col5.setPreferredWidth(35);
table.getColumnModel().getColumn(4).setCellRenderer(rightRenderer);
final int INDEX_COLUMN6 = 5;
TableColumn col6 = table.getColumnModel().getColumn(INDEX_COLUMN6);
col6.setPreferredWidth(820);
setLayout(new GridLayout(0, 1, 0, 0));
JScrollPane scrollPane = new JScrollPane(table);
this.add(scrollPane);
}
}