我正在嘗試使用按鈕將資料發送到JFrame命名UpdateCar。資料應該說明應該選擇哪個單選按鈕。
btnUpdateCar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
UpdateCar updatePage = new UpdateCar();
updatePage.setVisible(true);
int selectedRow = table.getSelectedRow();
updatePage.buttonGroup.setSelected(getSelectedButton(model,selectedRow).getModel(),true);
// when I use above line it doesn't work. But instead if I use the thing it will return, it works for that value.
}
});
為此,我寫了一個這樣的方法:
public JRadioButton getSelectedButton(DefaultTableModel model, int selectedRow) {
String selectedButton = (String) model.getValueAt(selectedRow,3);
UpdateCar updatePage = new UpdateCar();
if(selectedButton.equals("Automatic")) {
return updatePage.rdbtnAutomatic;
}else {
return updatePage.rdbtnManuel;
}
}
uj5u.com熱心網友回復:
好吧,顯然方法和 btnUpdateCar 的操作 perfrom 方法都應該對目標 JFrame 具有相同的參考。我對該 JFrame 使用了兩個不同的呼叫。現在我有那個 Jframe 的全域變數并且問題解決了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/406413.html
標籤:
