I have some code that creates a window with some buttons that when clicked prompt user for input via the console (Note: I'm running this in NetBeans). For now I want to keep using the console, so I'm not really looking for a solution where I create a new frame asking for input via a GUI.
The issue is that while console is taking input from the user the buttons are all still enabled and thus queue up any presses and those get executed when the user finishes inputting stuff into the console. I want to disable the buttons while the console is taking input. I thought the .setEnabled(false) method for buttons would do it, and I think normally it would. It seems that Java prioritizes user input and so the buttons don't get disabled until the user finishes inputting to the console. Once the user finishes input the buttons are supposed to get re-enabled anyways, so they are effectively never disabled. The code in question is below:
for(int i = 0; i < LABELS.length; i++) {
menu_a.add(new JButton(LABELS[i]));
menu_a.get(i).addActionListener((ActionEvent e) -> {
menu_a.stream().forEach((b) -> {b.setEnabled(false);});
menu_b.stream().forEach((b) -> {b.setEnabled(false);});
menu_c.stream().forEach((b) -> {b.setEnabled(false);});
if(!menu_a.get(menu_a.indexOf(e.getSource())).isEnabled()) {
MenuActions.MenuActions(menu_a.indexOf(e.getSource()) + 1, data);
menu_a.stream().forEach((b) -> {b.setEnabled(true);});
menu_b.stream().forEach((b) -> {b.setEnabled(true);});
menu_c.stream().forEach((b) -> {b.setEnabled(true);});
}
});
itemPanel.add(menu_a.get(i));
}
LABELS is just an array of strings which are the labels for the buttons.
MenuActions is a class that based on the index of the button prompts the user for different types of input via the console
data is an object that contains data that gets manipulated based on user input, not really relevant for the question I think.