1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
package com.explodingpixels.macwidgets;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import com.explodingpixels.data.Rating;
import com.explodingpixels.macwidgets.plaf.ITunesTableUI;
import com.explodingpixels.widgets.TableUtils;
public class DITunesTableUI {
private static TableUtils.SortDelegate createDummySortDelegate() {
return new TableUtils.SortDelegate() {
public void sort(int columnModelIndex,
TableUtils.SortDirection sortDirection) {
// no implementation.
}
};
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Object[][] data = new String[][] {
{ "All These Things I Hate (Revolve Around Me)",
"Bullet For My Valentine", "The Poison" },
{ "Cries In Vain", "Bullet For My Valentine",
"The Poison" },
{ "The End", "Bullet For My Valentine", "The Poison" },
{ "Her Voice Resides", "Bullet For My Valentine",
"The Poison" },
{ "Hit The Floor", "Bullet For My Valentine",
"The Poison" },
{ "Intro", "Bullet For My Valentine Apocalyptica",
"The Poison" },
{ "The Poison", "Bullet For My Valentine", "The Poison" },
{ "Room 409", "Bullet For My Valentine", "The Poison" },
{ "Spit You Out", "Bullet For My Valentine",
"The Poison" },
{ "Suffocating Under Words Of Sorrow (What Can I Do)",
"Bullet For My Valentine", "The Poison" },
{ "Tears Don't Fall", "Bullet For My Valentine",
"The Poison" },
{ "4 Words (To Choke Upon)", "Bullet For My Valentine",
"The Poison" },
{ "10 Years Today", "Bullet For My Valentine",
"The Poison" } };
data = new Object[][] { { Rating.FIVE_STARS, 4.0, "Cat" },
{ Rating.TWO_STARS, 3.0, "Dog" },
{ Rating.THREE_STARS, 8.0, "Parrot" },
{ Rating.ONE_STAR, 5.0, "Goat" },
{ Rating.FOUR_STARS, 2.0, "Tiger" }, };
// Object[][] data = new Object[][]{
// {1.0},
// {2.0},
// };
// JTable table = new JTable(new DefaultTableModel(data, new
// String[]{"Name", "Artist", "Album"})) {
JTable table = new JTable(new DefaultTableModel(data,
new String[] { "Rating", "Value", "Animal" })) {
@Override
public Class<?> getColumnClass(int column) {
if (column == 0) {
return Rating.class;
} else if (column == 1) {
return Double.class;
} else {
return Object.class;
}
}
};
// JTable table = new JTable(new DefaultTableModel(data, new
// String[]{"Name", "Artist", "Album"}));
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setUI(new ITunesTableUI());
// table.getColumnModel().getColumn(0).setPreferredWidth(150);
// table.getColumnModel().getColumn(1).setPreferredWidth(100);
table.getColumnModel().getColumn(0).setPreferredWidth(75);
table.getColumnModel().getColumn(1).setPreferredWidth(50);
table.getColumnModel().getColumn(0).setHeaderValue(new Icon() {
public void paintIcon(Component arg0, Graphics arg1,
int arg2, int arg3) {
}
public int getIconWidth() {
return 24;
}
public int getIconHeight() {
return 24;
}
});
TableUtils.makeSortable(table, createDummySortDelegate());
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBorder(BorderFactory.createEmptyBorder());
JFrame frame = new JFrame();
frame.add(scrollPane, BorderLayout.CENTER);
// frame.setSize(400, 265);
frame.setSize(275, 125);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
|