This might be a very simple thing that I'm overlooking, but I just can't seem to figure it out.
I have the following method that updates a JTable:
class TableModel extends AbstractTableModel {
public void updateTable() {
try {
// update table here
...
} catch (NullPointerException npe) {
isOpenDialog = true;
JOptionPane.showMessageDialog(null, "No active shares found on this IP!");
isOpenDialog = false;
}
}
}
However, I don't want isOpenDialog
boolean to be set to false until the OK button on the message dialog is pressed, because if a user presses enter it will activate a KeyListener
event on a textfield and it triggers that entire block of code again if it's set to false
.
Part of the KeyListener code is shown below:
public class KeyReleased implements KeyListener {
...
@Override
public void keyReleased(KeyEvent ke) {
if(txtIPField.getText().matches(IPADDRESS_PATTERN)) {
validIP = true;
} else {
validIP = false;
}
if (ke.getKeyCode() == KeyEvent.VK_ENTER) {
if (validIP && !isOpenDialog) {
updateTable();
}
}
}
}
Does JOptionPane.showMessageDialog()
have some sort of mechanism that prevents executing the next line until the OK button is pressed? Thank you.