JTable で JComboBox のセル レンダラーを作成しています。このクラスのコンストラクターはパラメーターを取らないでください。getTableCellRendererComponent メソッドの基本的なコードは次のとおりです。
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus,int row, int column)
{
if (value != null) {
removeAllItems();
value = value_to_string;
addItem(value);
if (isSelected) {
this.setForeground(table.getSelectionForeground());
super.setBackground(table.getSelectionBackground());
} else {
this.setForeground(table.getForeground());
this.setBackground(table.getBackground());
}
// Select the current value
this.setSelectedItem(value);
}
return this;
}
問題は、オブジェクトの代わりに、文字列オブジェクトの配列 (String[]) を値として持つことString[] value_to_string = (String[]) value
です。しかし、これにより例外エラーがスローされます。私が言ったように、コンストラクターにはパラメーターがあってはなりません。誰かがこの問題を解決する方法を見つけることができますか? 前もって感謝します!