[英]How can I use general string in Jspinner?
我在JSpinner上遇到问题以在JSpinner中显示Month,并且我遵循了以下代码。我使用带有jframe形式的swing控制来使用spinner控制。 当我运行项目时,始终将默认值设置为0。如何解决此错误?
static protected String[] getMonthStrings(){
String[] months=new DateFormatSymbols().getMonths();
int lastIndex=months.length-1;
if(months[lastIndex]==null || months[lastIndex].length()<=0){
String[] mS=new String[lastIndex];
System.arraycopy(months,0,mS, lastIndex,0);
return mS;
}
else{
return months;
}
}
public spinner(boolean CycleMonths) {
initComponents();
JTextField tf=null;
String[] monthStrings = getMonthStrings();
SpinnerListModel monthModel=null;
if(CycleMonths){
monthModel=new CycleSpinnerList(monthStrings);
}
else {
monthModel=new SpinnerListModel(monthStrings);
}
spMonth=new JSpinner(monthModel);
}
在构造函数代码中,您要调用initComponents,然后创建SpinnerListModel,创建新的JSpinner,但是从不将其添加到任何地方...所以看起来问题是您没有在任何地方添加JSpinner。
public spinner(boolean CycleMonths) {
initComponents();
JTextField tf=null;
String[] monthStrings = getMonthStrings();
SpinnerListModel monthModel=null;
if(CycleMonths){
monthModel=new CycleSpinnerList(monthStrings);
}
else {
monthModel=new SpinnerListModel(monthStrings);
}
spMonth=new JSpinner(monthModel);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.