1
我正在面對模擬按鈕點擊的問題。我有JTextField
從掃描儀獲取數據(如在雜貨店)。之後,我需要按下輸入按鈕,啓動功能jTextField1ActionPerformed
。有沒有辦法做到這一點,而不產生任何按鈕操作?根據jtextfield的變化模擬按鈕點擊
或者我需要提示如何在每次更改jTextField時jButton1.doClick()。 !請幫助:)
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
AddEmployee.add(jTextField1.getText());
jLabel7.setText(AddEmployee.name);
jLabel12.setText(AddEmployee.dep);
jLabel10.setText(AddEmployee.pos);
jLabel11.setText(AddEmployee.time);
num++;
jName.append("\n"+Integer.toString(num)+". "+AddEmployee.name);
jTime.append("\n"+Integer.toString(num)+". "+AddEmployee.time);
jTextField1.setText("");
}
catch (ClassNotFoundException | SQLException | ParseException ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
}
你在這裏找到你的答案了嗎? http://stackoverflow.com/questions/4419667/detect-enter-press-in-jtextfield –
這是我的主要觀點,程序必須沒有輸入工作) –
所以你想在jTextField1填充後立即觸發jButton1 ?如果是這樣,你不需要聽衆這樣做,只需在填寫文本字段的同時觸發按鈕... –