カートに追加する数量を選択しようとしています。たとえば、コンボ ボックスのドロップダウン リストは 1-10 と その他.. で構成されています. 10 個以上の製品を購入したい場合は、ドロップダウン リストから その他.. を選択すると、テキスト フィールドが表示されます。これは、javaFX でコンボボックスをセットアップする方法です。
<ComboBox fx:id="qtyComboBox" prefHeight="21.0" prefWidth="159.0" style="-fx-background-color:#D2B48C;" GridPane.columnIndex="1" GridPane.rowIndex="4">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="" />
<String fx:value="1" />
<String fx:value="2" />
<String fx:value="3" />
<String fx:value="4" />
<String fx:value="5" />
<String fx:value="6" />
<String fx:value="7" />
<String fx:value="8" />
<String fx:value="9" />
<String fx:value="10" />
<String fx:value="Others.." />
</FXCollections>
</items>
</ComboBox>
そして、これがコンボボックスから選択したアイテムを取得する方法です:
if(panel.getQtyComboBox().getValue().equals("Others..")){
panel.getQtyTextField().setVisible(true);
qty = Integer.parseInt(panel.getQtyTextField().getText());
}else{
qty = Integer.parseInt(panel.getQtyComboBox().getValue());
}
ただし、1-10 を選択すると、問題なくデータベースに挿入できます。しかし、Others.. を選択すると、テキスト フィールドが表示されません。私はどこで間違ったことをしたのだろうか。前もって感謝します。