Refresh JComboBox in one class when a changes JList in another class?

Hello
I have a small program where I am trying to update a JComboxBox in my class Main.java (a JFrame) when the contents of a JList change in another class JFrame, ProjectManager.java

I have three classes involved in the present.

Main
Poster of the JComboBox

ProjectManager
Displays the JList and here you can add/remove items in the JList
When this happens I want changes to be reflected in the main class

ProfileManager
The above two classes get their datamodel of this class by calling the static methods:
public static ListModel getProfileListModel()
and
public static ComboBoxModel getProfileComboboxModel()
I'm new to Java/Swing and I guess I'm must write a ListDataListener who warns 'Hand' that JList has changed.
Who update the JComboBox.

The problem is how to do that when I have three classes involved?

I tried to create this listener in the main class:
 class ProfileListDataListener implements ListDataListener {

        public void contentsChanged(ListDataEvent e) {
            getProfiles();
        }

        public void intervalAdded(ListDataEvent e) {
            getProfiles();
        }

        public void intervalRemoved(ListDataEvent e) {
            getProfiles();
        }
        
    }
getProfiles() looks like this:
private void getProfiles() {
cmbProfiles.setModel(profileManager.getProfileComboboxModel());
}
I can't add this listener to the ListDataModel since my class of earphone is not static, and if I do static, I can't call the method not static getProfiles().

Anyway, my question is, what is the right way to do it when I want to notify a listener in the main class of class ProjectManager?

Thank you.

There are several ways (and I hope at least one is correct)
You tell us how you want to update the drop-down list.
I guess it must reflect the content of the JList. Yet,.
I will describe the General.

1)
-you create hand declaring the combo as a global variable
-you create ProjectManager by passing a reference to hand
-join a listener JList of ProjectManager
When the listener fires, you have access to the drop-down list via the reference of hand and the update.

1A)
Rather than attach the listener to the JList, you can attach it to its model,
that might be in ProfileManager. In this case ProfileManager should have the
the reference to hand. -By the way: you have several instances of hand or ProjectManager?
I do not see the need for static methods in ProfileManager yet.

2)
-you create hand
-you create an instance of the ProjectManager and ProjectManager must declare his
JList as a global variable
-You can access this list via the instance of ProjectManager
-join a listener this list in hand and update the drop when the
lights of the listener.

2A)
Rather than attach the listener to the JList, you can attach it to its model,
that might be in ProfileManager. In the main case must have a reference to
ProfileManager.

I personally prefer to have the Jlist and its auditor in the same class.
And if my assumption is right that the combo should reflect the content of the JList,
There is no need of the ProfileManager class if his job is only to define models of
the JList and the JCombobox.

Tags: Java

Similar Questions

  • I have a desktop computer and a laptop. When I change a bookmark on one, it does not change on the other, even if I am connected to sync

    I have a desktop computer and a laptop.
    When I change a bookmark on one, it does not change the other even though I am connected to the sync.

    Sync is meant to do?

    Most probably one of the two computers has corrupted data which does not allow the sync complete.

    Refresh (called "Reset" in older versions of Firefox) can solve a lot of problems in restaurant Firefox as his default factory while saving your bookmarks, history, passwords, cookies, and other essential information.

    Note: When you use this feature, you will lose all the extensions, toolbar customizations, and certain preferences. See article Firefox Refresh - reset modules and parameters for more information.

    Refresh for Firefox:

    1. Open the troubleshooting information page using one of the following methods:

      • Click the menu button

        click Help

        and select troubleshooting information. Should open a new tab containing your troubleshooting information.

      • If you are unable to access the Help menu, type Subject: support in your address bar to bring up the troubleshooting information page.
    2. At the top right of the page, you should see a button that says 'Refresh Firefox' ('reset Firefox' in older versions of Firefox). Click on it.
    3. Firefox closes. Once the update process is complete, Firefox will display a window with the imported information.
    4. Click Finish and reopen Firefox.

    This corrects the problem? Please report to us!

    Thank you.

  • Windows security for the family and parental controls not update/refresh when you change curfews, no matter what I do

    I have windows 8 and 7, two different computers. When I change a curfew on the WFS Web site, our computers do not receive the update and do not allow access monitored accounts. On the 7 machine, I go to Windows Live Family Safety Filter, hit the icon refresh at the top right and a popup says I already have the last parameters, or FS settings have been updated. but in no case can the user log on. When the monitored user tries to connect, a message says "your account has time restrictions... ».  What's wrong???

    Here are the parameters:

    Hi Peter,.

    Welcome to the Microsoft Community forums.

     
    I understand when you do the curfew change on the site Web WFS, computers
    do not get the update and not allow access to the monitored accounts as you have
    two computer windows 7 and 8.

    Please follow the response of the Rudi on July 13, 2012.

    You can also go through the link on the safety of the family
     
    Keep us updated on the results.
  • I copied a title several times throughout a project on the same video track. I need to change one thing in each title, but when I change one thing on one, he turns them ALL. How can I avoid this?

    I copied a title several times throughout a project on the same video track. I need to change one thing in each title, but when I change one thing on one, he turns them ALL. How can I avoid this?

    dariusb

    What version of Premiere Elements and on what operating system works - it? At the moment a generalization...

    You need to create the title in the Titler, close the titration module, open the media project, right click on the thumbnail of the title in the media of the project and select duplicate.

    Then drag the duplicate to the timeline. Double-click the duplicate to open the titration module to change the title in doubles.

    If please examine, study and provide more information, so that I can refine (Customize) the answer for you.

    Thank you.

    RTA

  • Lighroom 5.4 develop view does not refresh when you change cursors

    Just updated to Lightroom 5.4 (using Adobe CC) on Win8. After "saw to develop" on any photo and change the exposure or any other cursor does not update the main view of the photo. He however update the thumbnail in the strip of film and the second monitor window correctly. I have tried everything I can think of:

    (1) demotion to 5.3 LR (which used to work)

    (2) force the regeneration overview standard and 1:1

    (3) uninstall the re - install Lightroom (5.3 and 5.4)

    (4) maximize the catalogue

    (5) remove the folder AppData Adobe

    (6) creating a new catalog with zero pictures, import a single photo and try to change exposure/contrast on this

    None of these results in the view to develop the image change when I change the cursors.

    Guys do you have experience with this?

    Hey entombed123,

    It seems that I found what the problem is - it's to follow the color profile. Attempt to set the default and check again. It worked for me and a few people who have had this problem before.

    Good luck.

  • How to configure the use of Thunderbird signature files to modify corresponding automatically when I change the sender of the e-mail?

    I have more than one email account that I use, and they associated different signature files. When I open the new email (no matter which account I'm opening of) it comes with my default signature and I can't change that.
    Is there a way to change this behave? Is it possible that the signature will change corresponding to the signature of the sender of email account when I change the sender?
    I hope that my question is simple, but if you have additional questions, do not hesitate to contact me please.
    Kind regards
    ERNO Horvath

    You should be able to implement a static email signature in each account settings. I suspect that it may become a little confused if you answer of in the local folders account; It will likely use the signature associated with the default account in Thunderbird. Also it messes up, I read, when using reply to all.

    I use the Signature Switch. Look out for additional features like hybrid sigs, so that you can have the plain text and html signatures format in a single file. It may also choose a signature function recipients/recipient rather than just the account used when creating the message.

    Some users prefer a tool Clipboard such as QuickText or clippings.

  • I teach online and all my classes have the same user name and password. Now that I clicked "remember me next time", I can connect only in one class. How to unlock my password. Carol in English

    I teach online and all my classes have the same user name and password. Now that I clicked "remember me next time", I can connect only in ONE class. How to unlock my login and my password, so that I can use it for all classes. Carol in English

    "Remember Me" for the site connections automatically when you return to the Web site is done with a Cookie the site in Firefox.

    Try to clear your Cookies for this Web site.

    Tools > Options-> life privacy - Cookies = the button show Cookies.

    You must use the custom settings for history at the top of this tab to see the View the Cookies button.

    Enter the domain name in the top search bar and all Cookies for this URL will be displayed. Unless you can figure out which is Cookie to "remember me", you will need to delete them all.

    Hold the {Ctrl} key while you click each Cookie in the small window. When this list is all highlighted, click the Cookie delete button at the bottom left.
    When you are finished click Close.

  • When to change the print cartridges...?

    How will I know if my ink cartridges for the printer are REALLY exhausted totatally (always feel after that computer says "low on ink"...?)   Can I change both cartridges (black anymore)- or is it all of the visuals to know when to change?  These cartridges are not cheap!

    Keep with them until print quality becomes unacceptable (washed, etc.).

    There is no need to change the cartridges, simply because one is empty. Just change the a void.

  • What exactly happens when you change the name of the computer, and it asks you to restart?

    What exactly happens when you change the name of the computer, and it asks you to restart - relating to the registration and identification of network?  Specifically when a computer isn't yet in one area but is still in a working group.  Y at - it show any PC by informing other computers it's name has changed?

    Computers into working groups are actively seeking each other, so if you rename a computer, it will not be shown anything. The restart is to erase the name of origin since the system cache, he will think that it's always the old name until the reboot takes place. Work computers is simply 'shake hands' with each other whenever they need to communicate.

    Computers that are part of a domain are created a 'computer' account that is assigned a random password that changes every 30 days by default automatically. These computer accounts work almost identical to an Active Directory user account, which means that they are not proactive they simply cached credentials with their permissions to provide if / when requested by heritage in the environment.
    Users and computers Active Directory accounts are stored in the NTDS. SAID the database, the backbone of an AD environment. When a computer name changes in one area, it takes the PC restarted simply for the PC. The change of name in Active Directory will replicate throughout the environment based on the settings of replication of this environment.
    I'm too simplify all this, but the general concept is there.
  • F6D33PA #AKL: my laptop is running slow when you change a new HARD drive

    My old HDD is dead, so I buy a new one and I change it. The problem is when I change to a new one and install Windows 8 64 Bit, when I finished installing it seems to be very slow and late, so I can't install any program because it is very slow. My Notebooke: HP Pavilion 14-n202tx Notebook PC CPU: intel core i5 RAM: 4 GB HARD drive: 1 TB

     
  • Disable Split Tunneling - SAs are not when I change crypto ACL

    Hello!

    When I change my ACL Crypto I receive an error message in phase I: "PROPOSAL_NOT_CHOSEN NOTIFIER' of IKE. I do this to disable the ST and get all the hollow tunnel traffic. Please see the config below:

    crypto ISAKMP policy 10

    md5 hash

    preshared authentication

    life 3600

    ISAKMP crypto key cisco address x.x.x.x

    !

    !

    Crypto ipsec transform-set esp - the esp-hmac-md5 ENCRYPTION

    !

    crypto map ipsec-isakmp CLIENT 1

    defined peer x.x.x.x

    game of transformation-CRYPTO

    match address 115

    !

    access-list 115 permit ip 10.10.10.0 0.0.0.255 10.10.11.0 0.0.0.255

    access-list 115 deny ip any one

    I changed the ACL 115 to so I can disable split tunneling, and it looks like this:

    access-list 115 permit ip 10.10.10.0 0.0.0.255 any

    access-list 115 deny ip any one

    What is a failure? I have donthink the crypto ACL must be the same?

    OK, you use a card dynamic encryption on your head just as I suggested, so that's fine. What you have done, which is causing your problem (and usually causes more problems than it's worth), is to assign an access list to the dynamic encryption card. It is not necessary, because with a dynamic encryption the router head card accept any model of traffic the remote router sends.

    In your case since you changed the remote router to be 'all', it is no longer maps to the 115 ACL on the head and now is failing.

    Way easier around it is simply to remove the 'match 115' address card dynamic encryption on the head. This will not affect any of your other tunnels and allow the remote router to establish a tunnel.

    The exact commands you would use are as follows:

    > crypto dynamic-map PERSONAL 10

    > no address for correspondence 115

  • Mail and sharing of WIndows 8 has stopped working when I changed my Yahoo password. Can't remove and replace the account information from Yahoo either. Any suggestions?

    I was doing very well with Windows 8 and really liked the tile part until the part of so many mail no longer works when I changed my Yahoo password (after having hacked).  Given that the Yahoo account has been used to set up my Microsoft Account for the new computer laptop / Windows 8, this old password appears to be caught in the trap in the system.  I can still use the browser to get to Yahoo use e-mail like this, but it is frustrating that the Mail tile is now useless and hand tile is too.

    Hello Rob,

    The Microsoft Account and Yahoo accounts are two separate accounts.  Then the two accounts use the same login ID (your Yahoo email address) and can be configured with the same password; When you change the password for one of the accounts that will not change your password for the account on the other.

    If the two accounts used the same password, I suggest to change the password for your Microsoft account and using a separate password for each.

    Once the Microsoft Account password has been changed, you should be able to connect to the mail. You may still need to update your email Yahoo mail password of: charms-> settings-> accounts-> .

    Mark

  • When I change a column is a primary key the associated non-unique index to become unique?

    So basically I already tried this and it shows me that the associated index is not unique.

    create table employees2 in select * from employees;

    create index emp_idx on employees2 (employee_id);

    ALTER employees2 table add primary key (employe_id) using index emp_idx;

    Select * from user_indexes where index-name = "EMP_IDX";

    I was wondering if I right assuming that when you change a column to a primary key or unique while using a given index that does not have the respective index become unique.

    The textbooks I use are sometimes a little hard to understand because of the wording, also, I want to just ask someone with a little more experience than me.

    Thank you.

    your test did give the correct answer: the index is not unique if it serves to bear a unique or primary key constraint. Indeed, it is one of the benefits of the use of no unique indexes in support of UK/PK constraints (since it allows to set the unusable index before to make bulk loads; and, of course, they have also some disadvantages - for example, they need an additional logical reading to reach a line). Richard Foote explains the details in https://richardfoote.wordpress.com/2008/06/04/primary-keys-and-non-unique-indexes-whats-really-happening/ (and other items).

  • When you change an item type only display in hidden element its value changes from any value in value null. Why?


    Dear reading

    When to change a display one item type in the hidden element its value changes from null value any value . Why?

    I would like to use the result of the query in the hidden item, as well as to display it in report footer.

    shortly the displayed element can read footer bu area hidden point cannot be viewved in the footer box. Why?

    footer

    & P11_DISPLAY_ONLY_ITEM.

    footer

    & P11_HIDDEN_ITEM.  )

    (site of apex.oracle.com Application Express 4.2.5.00.08)

    concerning

    Enformatik wrote:

    in the part of the properties point setting its source type as query retune unique value;

    but when you set its value to the calculation (before header) it works correctly.

    It is the expected behavior. The values defined in the properties of the Source element / by default are only put in the controls of the page displayed in the browser, not in session state. To refer to a session-state item value (as in a & P11_HIDDEN_ITEM. substitution of static text) then the value must be set in session state in a calculation or process that runs before the substitution reference is returned.

    Setting the value using a calculation is the right way to do it.

  • a string of numbers changing when you change a shape numbers

    I'm on a test run using Acrobat DC. When you change one or more of the numbers in a column loses its shape. I managed to change some PDFs using Acrobat DC, but some (from the source of the monthly information) won't let me change the numbers. What I am doing wrong?

    Hi tired:

    I looked at page 6 of your 15.06.23.pdf file. In fact, if you try to change 231-21, the formatting of the column gets disturbed. Then I tried to reduce the width of the box 'just enough' by entering the Central clamp on the right edge, then he restored the layout of numbers. Hope that works for you.

    Kind regards

    : RamB

Maybe you are looking for