corejava第9版
This commit is contained in:
1 parent
a900ff96aa
commit
75e83a331f
1025 files changed
+121606
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user