How to make GUI components feel the state of other objects?

I need my JButtons in any place of GUI be enabled or disabled depend on states of several objects or events generated by some other objects. Would you recommend the common approach of how it can be implemented in Swing?

Sorry for the delay, but the job that pay my bills is keeping me very busy today (taking a short break to reply to you) :)
Yes, the observers observable pattern is a good way to decouple this (but it could be overkill if you only want to update the status of one button). You will need to have references to the button variable so you can enable it / disable it from another place. For example, let's say you have an Class that extends the Observable and performs your heavy processing on a separate thread (Please not than I don't use generics here, just trying to quickly show you how you may want to do this):
import java.util.Observable;
public class TaskMan extends Observable {
    private List comp; 
    public void TaskMan (final List aComp) {
        comp = aComp; // Keep track of the components you want to to toggle on / off
    public void notifyObservers(Object arg) {
            setChanged(true);
            super.notifyObservers(arg);
    public void doIt() {
        new Thread (new Runnable() {
             public void run() {
                     notifyObservers(comp); // Dissable
                     // Your long consumming task here
                    notifyObservers(comp); // Enable
}Then you have the Observer class that enable / dissable the buttons and other components:
import java.util.Observer;
import java.awt.Component;
public class MyObserver implements Observer {
     public void update(Object observable, Object arg) {
             if (! (arg instanceof List)) {
                 return;
             List list = (List) arg;
             for (Object elem: list) {
                    Component comp = (Component) elem;
                    EventQueue.invokeLater(new Runnable() {
                           public void run() {
                                 comp.setEnabled(! comp.isEnabled());
}And finally your main class, where you create and put together your GUI, register your observers and you call your long time consuming job
import java.util.*;
public class MyApp {
    public static void main(String [] args) throws Exception {
              List comps = new ArrayList();
              JButton aBtn = new JButton("Hey dude!");
              comps.add(aBtn);
              TaskMan task = new TaskMan(comps);
              task.addObserver(new MyObserver());
              task.doIt();
}Looks like you have several use cases there, maybe you want to try this approache first for some of them, adding more logic to the observer.
Please reply back, let me know what you think.
Regards,
Jose.

Similar Messages

  • How to make a cell populate the same as other cells mac numbers

    does anyone know if theres a command where I can make a cell be the same value as another cell? so i change one cell and it populates the same in others. Thanks!

    Hi appleryan,
    =A1
    in any cell will bring the value of A1 into that cell.
    quinn

  • How to make type flow with the shape of an object?

    Hi there,
    I am a bit of an Illustrator newbie. I am needing some help to work out how to wrap or manipulate type to fit the shape and flow of an object? I have attached an image to show you what I am trying to do. I want the "shop by measure" text to be in the yellow blank space of the tape measure but flowing with the shape of the tape. Any help appreciated! Be gentle please lol.

    See online help. Read about Envelope Distortion. Then keep things simple as you experiment. This takes about 2 minutes.
    When doing "ribbon distortions," selecting corresponding top and bottom MeshPoints as pairs and moving/scaling/rotating them together helps avoid things getting all distorted out of control. See this PDF for an example. The example was done using a 1 Row, 2 Column Mesh.
    JET

  • How to make users to select the date from calendar control my making the date field read only in date time control in external list in sharepoint 2010

    How to make users to select the date from calendar control only, by my making the date text field read only (don't want to let users type the date) in date time control in external list in sharepoint 2010. I am looking for a solution which can
    be done through sharepoint desginer / out of the box.
    thanks.

    Congratulate you got the solution by yourself. I am new to a
    WinForms calendar component, I feel so helpless on many problems even I'd read many tutorials. This question on the
    calendar date selection did me a great favor. Cheers.

  • How to make JDev aware of the xmldb API

    Hi everybody,
    I am a real beginner in Jdev, and I have to develop a
    Java Application using Oracle Java developer, against
    an XML-native database called eXist. I'll have to use
    a java API called xmldb supported by eXist in order to
    interact with the database. Although I have basic
    knowloedge in Object-oriented programming, but I don't
    know where to begin, especially how to make JDev aware
    of the xmldb API, and how to create classical
    application components (Windows, buttons, etc).
    Could you help me with some orientations and
    interesting links?.
    Thanks a lot.
    Mounir.

    Hi,
    don't know this database, but the database vendor should be able to explain how his DB is accessed from Java. If this requires libraries, then the vendor will provide these in JAR files, which you then configure with JDeveloper (as a custom library Tools --> Manage Libraries) or in the Project
    If there is a JDB driver for it, even better. This however is not a deliverable of JDeveloper but the database vendor
    Frank

  • How to make a look & feel

    I want make a look and feel like available in the pic. In the Below Link
    http://ddsuresh.150m.com/controls.jpg
    Anybody can give a idea.

    I went through that website. But still i did not the look and feel what I need.
    http://ddsuresh.150m.com/index.html
    Once again visit the above website and give ur ideas. How to make look and feel.

  • How to make Nokia Suite remember the position and ...

    how to make Nokia Suite remember the position and the size i set it?
    because everytime i start it, it defaults in the middle of the screen and in the smallest possible size.
    Nokia Suite 3.3.86
    Windows Vista
    Greece Nokia X6 RM-559 v40.0.002

    Again, are you talking about genuine Nokia firmware, not any of some 3rd-party customised versions?
    For officially released firmware, you may force Nokia Suite to reinstall even if your firmware is already up to date. This feature might be missed in its GUI as its link is "hidden" in the prompt message, not on a button or highlighted with underscore. Try Nokia Suite, once the phone is connected, click the icon of Software Update on the top, then click the word "reinstall" in the prompted message.
    bbao
    * If this post helped you, please click the white Kudo star.
    * If this post has solved your issue, please click Accept as Solution.

  • How to make text start at the top of a page in livecycle 9

    Hi, How can I get the text in a large text field to start at the top left of the field rather than at the center of the field? In addition, may one know how to make text wrap in the form as well?
    Thanks,
    David

    To set the Text alignment properties use "Paragraph" pallet you can make it visible by selecting Window>>Paragraph or Shift+F5
    And to allow text wrapping you need to select "Allow Multiple Lines" checkbox under "Object" pallet and "Field" tab. You can make Object pallet visible by selecting Window>>Object or Shift+F7.
    Good Luck,

  • I subscribed for itunes imatch - it works perfectly on my i-pad and iPhone - however on my macbook - my iTunes can no longer find my songs - i don't know how to make it look to the cloud to play my music

    i subscribed for itunes imatch - it works perfectly on my i-pad and iPhone - however on my macbook - my iTunes can no longer find my songs - i don't know how to make it look to the cloud to play my music - i think it keeps trying to find on the external harddrive where i used to keep my music

    Of course iTunes is looking for the music on the external HDD. Enabling iTunes Match does not magically change the location of the iTunes library to the cloud.
    To play the music either plug the external HDD back into your computer or create a new, empty library to use for streaming the iTM content. The latter can be accomplished by holding down the Option key when launching iTunes, choosing "create library" then enabling iTunes Match on the new library. DO NOT have iTunes scan your HDD for music.

  • How to make a restart of the workflow in a process controlled workflow?

    Hi Experts,
    How to make a restart of the workflow in case of process controlled workflow? Scenario is like this:
    The user has created a shopping cart with 1000 USD. The process schema has three process level with the first level being approval with completion.
    The first level being executed by the responsible purchaser. Here, the purchaser adds the source of supply and changes the price of the shopping cart 2000 USD and approve the shopping cart.
    Now, I want the approval task to start from beginning so that the requestor can know the changes and accept/reject the changes.
    Thanks and regards,
    Ranjan

    Hi,
    Restarting workflow goes to 1st level approval step. It is not requester.
    I think you need to set condition for "Acceptance by Contact Person" in Define Process Level.
    Regards,
    Masa

  • How to make a backup if the Storage & Backup icon is missing?

    how to make a backup if the Storage & Backup icon is missing?

    http://www.apple.com/icloud/setup/ios.html
    Sounds like you have an account, so two options I would say.
    Try turning it off, then off and see what options you get, or sync your phone to iTunes and click on the summary and choose the iCloud option.

  • How to  make adding attachments in the oaf page mandatory  to the user.

    Dear Friends
    I did a attachment section with item style as attachment table,entity map,primary  key concept in my details page
    But  I want to   make this section (adding attachments in the oaf page)  mandatory  to the user.
    Without adding the attchment user should not click SUBMIT.
    [ Just like we give  REQUIRED  property to ant text input fileds  to make entering them mandatory , Is there any property to set ]
    Please share ur ideas .Please help.
    Thanks
    Aravinda

    Gyan's Oracle Application Framework Blog: OAF - Making mandatory Attachement Mandatory
    iWiDi - This is how to make attachments mandatory in iExpense.
    --Sushant

  • How to make every account in the system login automatically?

    How to make every account in the system login automatically when Mac OS X startup?
    Thanks!

    I can see one way to do it. You'll need to install a script in each user account, and have it set as a login item for each user. Let's imagine you have three user accounts. Each user in Mac OS X has a UID number. Normally your first user has the UID of 501, the second one will be 502 and so on...
    You can determine the UID by running the following AppleScript while logged in on each user:
    do shell script ("ID")
    This'll return a long block of text, but right at the start you'll see the UID number. Let's assume your three users have the UIDs 501, 502 and 503. We begin with 501.
    Create the following script and save it as an application while logged in as 501. Note that the password you're entering is the password for UID 502. Also note that the forum system is creating line breaks where there shouldn't be any. The long "do shell script" line should be one line.
    delay 5 --This delay allows time for login to complete, but it may not be necessary.
    try
    do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 502"
    delay 5 --This delay could be shorter or longer, depending on how fast your machine is.
    tell application "System Events"
    keystroke "password for 502" --the password for UID 502
    keystroke return
    delay 1
    end tell
    on error
    display dialog "Unable to switch user."
    end try
    Open System Preferences, go to Accounts, click "login items" and drag your script (saved as an application) to the login items window.
    You basically repeat this process for each user account, modifying the script so it switches to the next user.
    This isn't ideal, because your passwords will be stored in the scripts, and each user could open the scripts and learn the passwords of the other users on that machine.
    I picked some of this up from a discussion over at the Macworld forums:
    http://hints.macworld.com/article.php?story=20031102031045417
    Message was edited by: The Preacher
    Message was edited by: The Preacher
    Message was edited by: The Preacher

  • How to reuse some components of the scripts layout to other programes

    how to reuse some components of the scripts layout to other programes

    You can't reuse components; the only solution would be to copy a script and to remove all components not needed.
    Regards,
    John.

  • HT4623 How to make Google Maps as the default Map App in my iPhone 5

    How to make Google Maps as the default Map App in my iPhone 5, so that I could still use the old bookmarks and use the pins to drop, Please assist.

    You cannot make Google Maps the default mapping app.

Maybe you are looking for

  • A query about Time Capsule, Ethernet, and DSL modems...

    When I originally set up my modem, I used the network assistant and it seemed to "auto-connect", where the assistant tells you that your ISP "may allow you" etc. This was done with the ethernet cable as Modem to Macbook Pro. Then when I purchased a T

  • Issue in loading master data in BI 7.0

    Hi, I fail to understand how to load master data in BI 7.0. Can you please fill in the steps. 1. Created an Infoarea. 2. Created 2 infoobject catalogs ( for char and kf) 3. Created characteristics like empname and month and salary as KF. 4. For empna

  • Replication of product master and Product category

    Hi Please let me know steps involved in replicating Product master and product category from R/3 to SRM Regards Ashish

  • Disable the check box

    Hi All, I have a requirement in which based on the profile option user should be able to change the value of check box. Name of profile option is acces_level. In this user level profile option two values are possible 'User' or 'Administrator' and the

  • I am unable to update my PC browser

    It starts then I get an interruption code telling me it is unable to complete