我正在 Netbeans 中构建一个小型应用程序,我使用 JSpinner 组件来设置产品的数量。如何将微调器设置为仅取正值?Netbeans 内是否有我可以设置的选择或方法JSpinner
?
EXTRA:
spinner.setModel(new SpinnerNumberModel(0, 0, 20, 1));
for JSpinner http://download.oracle.com/javase/tutorial/uiswing/components/spinner.html你必须实施微调器编号模型 http://download.oracle.com/javase/6/docs/api/javax/swing/SpinnerModel.html
import javax.swing.*;
public class SpinnerModelTest {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SpinnerModelTest().makeUI();
}
});
}
public void makeUI() {
SpinnerModel modeltau = new SpinnerNumberModel(0.0002, 0.0001, 100.0000, 0.0001);
JSpinner spinner = new JSpinner(modeltau);
((JSpinner.NumberEditor) spinner.getEditor()).getFormat().setMaximumFractionDigits(4);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(spinner);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)