jkteater
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.setPreferredS ize(new Dimension(100, 20));
if (checkProject == 1) {
threeDButton.setEnabled(tr ue);
}
else {
threeDButton.setEnabled(fa lse);
}
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?
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.setPreferredS
if (checkProject == 1) {
threeDButton.setEnabled(tr
}
else {
threeDButton.setEnabled(fa
}
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?
The buttons should be enabled by one of the Project controls listeners
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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
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
Yes
>>Set the listener to run when the value of currentPorject is changed?
That would have automatically
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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
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
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
ASKER
Both suggestions was helpful
:)