1
keyTypedメソッドのifチェックの内側には貸し付けません。コードのfollowiing部分があります:編集可能か確認するjcombobox
ここ私はコンボボックスを初期化:
私が入力したかどうか確認この時点でprivate void initComponents()
{
this.cboDayModel = new DefaultComboBoxModel<ListItem>();
this.cboDay = new JComboBox<ListItem>(this.cboDayModel);
this.cboDay.addItemListener(this);
this.cboDay.setName("cboDay");
this.cboDay.setBackground(this.einAusClass.hPHB.btnColor);
this.cboDay.setEditable(true);
this.cboDay.getEditor().getEditorComponent().addKeyListener(this);
this.cboDay.getEditor().getEditorComponent().addFocusListener(this);
this.add(this.cboDay);
}
:keyTypedに方法は
@Override
public void keyTyped(KeyEvent e)
{
if (!(Character.isDigit(e.getKeyChar())))
{
e.consume();
return;
}
if (e.getSource() instanceof JComboBox) // <-------*************
{
System.out.println("zz2");
this.cbo = (JComboBox<ListItem>) e.getSource();
String str = ((JTextField) cbo.getEditor().
getEditorComponent()).getText();
int zahl = Integer.parseInt("0" + str);
System.out.println(str + "" + zahl);
if (this.cbo == cboDay)
{
if (zahl < 1 || zahl > 31)
{
e.consume();
return;
}
}
}
}
私は
をチェックしますかif (e.getSource() instanceof JComboBox)
なぜこのif文の中に入りませんか?
e.getSource()