62,634
社区成员




public class T1 extends JComboBox implements TableCellRenderer {
public T1() {
setBorder(BorderFactory.createEmptyBorder());
addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自動生成されたメソッド・スタブ
System.out.println("gggg");
}
});
}
public static void main(String[] args) {
JFrame f = new JFrame();
// try {
// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
// } catch (Exception e) {
// e.printStackTrace();
// }
JComboBox comboBox = new JComboBox();
comboBox.setBorder(BorderFactory.createEmptyBorder());
comboBox.addItem("Item-1");
comboBox.addItem("Item-2");
comboBox.addItem("Item-3");
comboBox.addItem("Item-4");
// comboBox.addItem("Item-5");
comboBox.setFocusable(true);
DefaultCellEditor editor = new DefaultCellEditor(comboBox);
JTable table = new JTable(5, 5);
table.getColumnModel().getColumn(0).setCellRenderer(new T1());
table.getColumnModel().getColumn(0).setCellEditor(editor);
JScrollPane sp = new JScrollPane(table);
f.getContentPane().add(sp, BorderLayout.CENTER);
JComboBox cmb1 = new JComboBox();
cmb1.setBorder(BorderFactory.createEmptyBorder());
cmb1.addItem("Item-1");
cmb1.addItem("Item-2");
cmb1.addItem("Item-3");
cmb1.addItem("Item-4");
cmb1.addItem("Item-5");
// cmb1.setFocusable(true);
f.getContentPane().add(cmb1, BorderLayout.SOUTH);
JComboBox cmb2 = new JComboBox();
cmb2.setBorder(BorderFactory.createEmptyBorder());
cmb2.addItem("Item-1");
cmb2.addItem("Item-2");
cmb2.addItem("Item-3");
cmb2.addItem("Item-4");
cmb2.addItem("Item-5");
cmb2.setFocusable(true);
f.getContentPane().add(cmb2, BorderLayout.NORTH);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
this.removeAllItems();
this.addItem(value);
return this;
}
}