擴展編輯功能由ComboBoxEditor
提供的,這允許您定義實際使用的組件作爲組合框的編輯
根據您的要求,您會需要(至少是)一個JTextArea
,提供(可選)自動換行,多行
粗略的例子可能是這個樣子......
public class TextAreaComboBoxEditor implements ComboBoxEditor {
private JTextArea ta = new JTextArea(4, 20);
private JScrollPane sp = new JScrollPane(ta);
public TextAreaComboBoxEditor() {
ta.setWrapStyleWord(true);
ta.setLineWrap(true);
}
@Override
public Component getEditorComponent() {
return sp;
}
@Override
public void setItem(Object anObject) {
if (anObject instanceof String) {
ta.setText((String) anObject);
} else {
ta.setText(null);
}
}
@Override
public Object getItem() {
return ta.getText();
}
@Override
public void selectAll() {
ta.selectAll();
}
@Override
public void addActionListener(ActionListener l) {
}
@Override
public void removeActionListener(ActionListener l) {
}
}
這並不支持ActionListener
,作爲JTextArea
使用輸入它自己的目的關鍵。如果你願意,你可以使用key bindings API添加自己Action
能夠觸發ActionListener
S,對於這一點,你需要提供一個List
或其他手段來管理他們,所以你可以叫他們回來
請,發佈[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)與您的問題 –