refreshing a dialog?

Posted on 2011-10-06
Medium Priority
Last Modified: 2012-05-12
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) {
       else {
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?
Question by:jkteater
  • 4
  • 3
  • 2
LVL 86

Expert Comment

ID: 36924733
The buttons should be enabled by one of the Project controls listeners
LVL 86

Accepted Solution

CEHJ earned 400 total points
ID: 36924789
The 'proper' way of doing it would be to make the buttons listen for a change for the 'project' or 'selectedProject' property of whatever class contains that property:


Author Comment

ID: 36924931
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 86

Expert Comment

ID: 36925441
>>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?

That would have automatically
LVL 47

Assisted Solution

for_yan earned 400 total points
ID: 36925617
Your buttons should have normal ActionListener attached.
When you click the button - I jguess you popup the dialog where the user selects the project - in that dialog you should have a method
which should set enabled -disables on these buttons in the original winodw simultaneously with changing the text
in this original winodw.
You just pass a a varaibale holding original dialog to the pop-up dioalog and through that varaible pointing at the instance of original dialog you
can modify properties of the elements - button textboxes of the original window
LVL 47

Expert Comment

ID: 36925631
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
LVL 47

Expert Comment

ID: 36925650
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

Author Comment

ID: 36927410
Both suggestions was helpful
LVL 86

Expert Comment

ID: 36927556

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question