corejava第10版

This commit is contained in:
deyou committed 2019-05-22 19:31:49 +08:00
1 parent 2021c3c227
commit 6165543dd3
1088 files changed
+94411

No files matched your search

@@ -0,0 +1,44 @@
package tableCellRender;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
/**
* This frame contains a table of planet data.
*/
public class TableCellRenderFrame extends JFrame
{
private static final int DEFAULT_WIDTH = 600;
private static final int DEFAULT_HEIGHT = 400;
public TableCellRenderFrame()
{
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
TableModel model = new PlanetTableModel();
JTable table = new JTable(model);
table.setRowSelectionAllowed(false);
// set up renderers and editors
table.setDefaultRenderer(Color.class, new ColorTableCellRenderer());
table.setDefaultEditor(Color.class, new ColorTableCellEditor());
JComboBox<Integer> moonCombo = new JComboBox<>();
for (int i = 0; i <= 20; i++)
moonCombo.addItem(i);
TableColumnModel columnModel = table.getColumnModel();
TableColumn moonColumn = columnModel.getColumn(PlanetTableModel.MOONS_COLUMN);
moonColumn.setCellEditor(new DefaultCellEditor(moonCombo));
moonColumn.setHeaderRenderer(table.getDefaultRenderer(ImageIcon.class));
moonColumn.setHeaderValue(new ImageIcon(getClass().getResource("Moons.gif")));
// show table
table.setRowHeight(100);
add(new JScrollPane(table), BorderLayout.CENTER);
}
}