2

I have two cards in a cardlayout and a button that allows one to go back and forth. How can I make the button inactive once it is clicked once so that the user can't go back to the previous card?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Maydayfluffy
  • 427
  • 1
  • 7
  • 16

4 Answers4

2

You can disable the button (in your action listener)

button.setEnabled(false);
objects
  • 8,637
  • 4
  • 30
  • 38
2

To make a button inactive, do:

JButton b = new JButton("BUTTON");
b.setEnabled(false);

and the button will not accept clicks.

Java42
  • 7,628
  • 1
  • 32
  • 50
2

JComponent#setEnabled(false)

Jeffrey
  • 44,417
  • 8
  • 90
  • 141
2

You could add an event handler to the click event of the button and disable it with button.setEnabled(false); in the event handler.

joshuahealy
  • 3,529
  • 22
  • 29