ユーザーが。のブールセルをクリックしてテキストフィールドに入力できるようにするコードを少し作成しようとしていますJTable
。
プログラムにテーブルのデータをテキストフィールドに入力させることはできますが、これを行う現在の方法には、奇妙な理由でテーブルがチェックボックスの値を変更できないようにするJOptionPaneが含まれます(つまり、チェックボックスは変更しません。 t黒からチェックマークに変更します)。これだけでなく、選択は更新されないため、選択によってtrueに切り替えられたとしても、最後の列の値はfalseのままになります。
JOptionPane
どういうわけか選択イベントをオーバーライドすることと関係があるのではないかと思いますが、そのJOptionPane
オブジェクトについては、その方法を説明するのに十分な知識がありません。私のコードは次のとおりです。
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
ListSelectionModel selectionModel = table.getSelectionModel();
selectionModel.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
if (lsm.isSelectionEmpty()) {
//no rows are selected do nothing
} else {
//First find the row clicked
int selectedRow = lsm.getLeadSelectionIndex();
/*
* put a popup here to ask the user which peak to associate
* the energy with.
*/
System.out.println(selectedRow);
//Get user to associate with a peak
availablePeaks = getAvailablePeaks();
String returnVal = (String) JOptionPane.showInputDialog(
null,
"Select the peak:",
"Peak Matching",
JOptionPane.QUESTION_MESSAGE,
null,
availablePeaks, null);
System.out.println(returnVal);
//Determine the selection
int index = 0;
for (int i = 0; i < availablePeaks.length; i++) {
if (availablePeaks[i] == returnVal) {
index = i;
} else {
}
}
//Set the peak value in the peak specifier to the energy in the row
double energy = (Double) table.getValueAt(selectedRow, 0);
System.out.println(energy);
frame.getPeakSetter().getPeakSpecifiers()[index].setEnergy(energy);
frame.getPeakSetter().getPeakSpecifiers()[index].getTextField().setText("" + energy);
}
}
});
のがテーブルのチェックボックスの更新を停止するJOptionPane
理由を誰かが知っていますか?ListSelectionListener
ありがとう!