这是我第一次尝试创建自定义swing组件。我正在尝试创建一个JComboBox,它将用于JTable中的众多单元。显示我的JTable时,应该包含组合框的单元格看起来是正确的。 但是,当我单击任何框时,列表不会显示。什么都没发生。这是我的代码:
public class TimeLineComboBox extends JComboBox<String> {
/**
*
*/
private static final long serialVersionUID = 1L;
private String item="";
private TimelineRecord timeLine=null;
public TimeLineComboBox(String[] list_,TimelineRecord timeLine_,String item_,Boolean editable_) {
super(list_);
this.addActionListener(listener());
timeLine=timeLine_;
item=item_;
}
private ActionListener listener() {
ActionListener actionListener=new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@SuppressWarnings("unchecked")
String value=(String) ((JComboBox<String>) e.getSource()).getSelectedItem();
switch(item) {
case "meat":
timeLine.meat=value;
break;
case "monitor":
timeLine.monitor=Configuration.getInstance().getMonitorByName(value);
break;
case "pit":
timeLine.pit=Configuration.getInstance().getMonitorByName(value);
break;
case "event":
timeLine.eventText=value;
break;
default:
JOptionPane.showMessageDialog(GUI.getInstance().getFrame(),"Internal Error: Unknown selection list: "+item,"Internal Error",JOptionPane.ERROR_MESSAGE);
}
}
};
return(actionListener);
}
}