简体   繁体   中英

show value JSpinner from JTable

i want to linked JSpinner with JTable. if i want to click a row in JTable, value in JSpinner change with value in that row JTable. I have source code like this :

 void select(){
     try{
        int row = TabelKebutuhan.getSelectedRow();

        txtJumlahButuh.setValue(TabelKebutuhan.getModel().getValueAt(row,0).toString());
        txtJumlahAda.setValue(TabelKebutuhan.getModel().getValueAt(row,1).toString());
    }catch(Exception e){}
}

but, thats source code can't work like i want. so, what the solution for this case?

Try this :

txtJumlahButuh.setValue(Integer.parseInt((String)TabelKebutuhan.getValueAt(row,0)));
txtJumlahAda.setValue(Integer.parseInt((String)TabelKebutuhan.getValueAt(row,1)));

try replace variable as needed setModel(new javax.swing.SpinnerNumberModel(Integer.parseInt((String) value), 0, 15, 1));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM