Link to home
Start Free TrialLog in
Avatar of jkteater
jkteaterFlag for United States of America

asked on

refreshing a dialog?

What would be the best way to go about this issue I am having.  On my dialog I have 4 change buttons.

Project:  [   text   ]   [ change ]
3d:         [   text   ]   [ change ]
2d:         [   text   ]   [ change ]
Email:     [   text   ]   [ change ]

When the dialog is created the only button enabled is change project.  The bottom 3 fields are based off what project is selected, so that can not change the values until a project is selected.
The value for Project when the dialog is created is "NO SELECTED PROJECT" - I will then click the change project button and select a project.  Right now all the bottom fields are populated and I want the change buttons for them to now be enabled.

so I wrote a if statement around the enable piece of code for the buttons

     final JButton threeDButton = new JButton("Change");
      threeDButton.setPreferredSize(new Dimension(100, 20));
      if (checkProject == 1) {
            threeDButton.setEnabled(true);
       }
       else {
             threeDButton.setEnabled(false);
       }
but the dialog is never created again or redrawn to where this way will work.  Not sure it is good practice to refresh your main dialog often.
What do you think is the best way to do this check?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

The buttons should be enabled by one of the Project controls listeners
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jkteater

ASKER

So you have a propertychange listener and in the listener action you would set all the buttons to enabled?
Set the listener to run when the value of currentPorject is changed?

I have never seen a property Change listener before
>>So you have a propertychange listener and in the listener action you would set all the buttons to enabled?

Yes

>>Set the listener to run when the value of currentPorject is changed?

That would have automatically
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Keep in mind though that just enabling - diosabling buttons affects only theur appaerance - if you want to enable/disable theier action
you need  remove the listener to disable and add the listener to enable
In general if it is about selecting the project from the list - consider JComboBox rather than the button with additional window popping up.
With JComboBox you can add ItemListener and use it to monitor if project is slecetd or not - I think it would be easier than with buttons, unless
the selctinon fo theproject is mnore sophistuicated than juts selecting form a list
Both suggestions was helpful
:)