Given the following code, how do I store the selected value from the spinner in thickness1
?
JSpinner thickn=new JSpinner();
thickn = new JSpinner(new SpinnerNumberModel(1, 1, 60, 1));
thickn.setFont(new Font("Arial Sans-seriff", Font.BOLD, 12));
thickn.setBounds(120,105,100,25);
// ...
int thickness1 = (Integer) thickn.getValue();
Is there an code I can add at the 3 dot region to retrieve the value from the spinner?
In your last line, try
int thickness1 = ((SpinnerNumberModel)thickn.getModel()).getNumber().intValue();
If you want to be more explicit, you can add the following where you have the three dots, it will do the same thing as the line above
SpinnerModel model = thickn.getModel();
SpinnerNumberModel numberModel = (SpinnerNumberModel)model;
Number number = numberModel.getNumber();
int thinkness1 = number.intValue();
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.