user3376738
user3376738

Reputation: 3

disable and enable buttons on Java

I have a form with many data. In this form the user can click on "view report" button which will load a pdf file from the folder, if the report exists.

I'm trying to find a way that the button will appear flat and won't be able to click it if there is no report to load and the button will appear regular and will be abled to click on if the report exists and can be load.

basically i'm trying to avoid clicking on the button in any case and if the report exists it will be loaded and if not it will gives an error msg.

The goal is that just by looking at the button the user will know if there is a report or if there isn't.

How can I make it possible assuming I have 2 images ready (flat and regular).

Upvotes: 0

Views: 88

Answers (2)

Jurko Guba
Jurko Guba

Reputation: 638

if (fileExists)
   JButton.setEnabled(true):
else
   JButton.setEnabled(false);

Upvotes: 2

D-Klotz
D-Klotz

Reputation: 2073

Have you thought of just using:

myButton.setEnabled(false);

and later when it's ok to use the button:

myButton.setEnabled(true);

Upvotes: 1

Related Questions