Can anyone help me to set a KeyPress
action on a currently opened jInternalFrame
?
I have a jDesktopPane
inside a jframe
, and I have multiple jInternalFrame
inside the DesktopPane
. I am using Netbeans to create this application.
On the jDesktopPane
I have 3 buttons to open 3 jInternalFrame
, and I created a Keypress
on those buttons and it works fine using this code:
private void formKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
if(evt.getKeyCode()==KeyEvent.VK_F3){
frmLogistics.setVisible(true);
frmLogistics.toFront();
}
}
A jInternalFrame
is open and inside there's a jtoolbar
with sets of buttons, one of it is a close button to close that opened jInternalFrame
. I set up the code for its ActionPerform
so when a user clicks that button the frame or window will be closed.
The problem now is how about a keyboard press? I want to trigger that close button inside the toolbar in a internalframe in order to close it
I tried this code:
private void btnCloseLogisticsKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
if(evt.getKeyCode()==KeyEvent.VK_F4){
int type = JOptionPane.YES_NO_OPTION;
int choice = JOptionPane.showConfirmDialog(this,"Do You Want to Log Out?","Exit Logistics System", type);
if(choice == JOptionPane.YES_OPTION){
frmLogistics.setVisible(false);
frmLogIn.show();
btnCashier.setEnabled(false);
btnTrucking.setEnabled(false);
btnAccounting.setEnabled(false);
}
}
}
But nothing happens. I tried to put that code inside jtoolbar
, jInternalFrame
and still nothing happens. Maybe anyone of you could help me?