Cześć.
Dany jest przykład z kisążki:
class PlanetTableFrame extends JFrame
{
public PlanetTableFrame()
{
final JTable table = new JTable(cells, columnNames);
add(new JScrollPane(table), BorderLayout.CENTER);
JButton printButton = new JButton("Print");
printButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent event)
{
try
{
table.print();
}
catch (java.awt.print.PrinterException e)
{
e.printStackTrace();
}
}
});
JPanel buttonPanel = new JPanel();
buttonPanel.add(printButton);
add(buttonPanel, BorderLayout.SOUTH);
}
private String[] columnNames = { "Planet", "Radius", "Moons", "Gaseous", "Color" };
private Object[][] cells =
{
{ "Mercury", 2440.0, 0, false, Color.YELLOW },
{ "Venus", 6052.0, 0, false, Color.YELLOW },
{ "Earth", 6378.0, 1, false, Color.BLUE },
{ "Mars", 3397.0, 2, false, Color.RED },
{ "Jupiter", 71492.0, 16, true, Color.ORANGE },
{ "Saturn", 60268.0, 18, true, Color.ORANGE },
{ "Uranus", 25559.0, 17, true, Color.BLUE },
{ "Neptune", 24766.0, 8, true, Color.BLUE },
{ "Pluto", 1137.0, 1, false, Color.BLACK }
};
private static final int DEFAULT_WIDTH = 400;
private static final int DEFAULT_HEIGHT = 200;
}
ponoć wywołanie metody
table.setAutoCreateRowSorter(true)
powoduje automatyczne sortowanie wierszy kiedy klikniemy na nagłówek kolumny.
Mi wychodzi że nie bardzo.
Na pewno sortuje alfabetycznie nazwy planet - czy w takim razie sortuje tabelę według pierwszego obiektu w wierszu czy jak? Bo tylko po naciśnięciu tego nagłówka sortuje.
Taka błahostka a nie daje mi spokoju.
Ktoś coś wie na ten temat, coś?