Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JComboBox used to update a JLabel

807598Jan 8 2006 — edited Jan 8 2006
Hi Folks,

I have a Combo box, with a list of contact names... When I select a name from the combo box it currently prints the selected name into my JAva Console. So I know the actionPerfomed and SetActionCommand etc... are all wired up correctly.

What I would like it to do is rather than print the name to the console. I'd like it to update a JLabel. (that is currently, intentionally blank, for this purpose)

Heres some code snippets that I hope help you understand what I have done so far.


**THIS IS FROM MY Controller.java CLASS**
public synchronized void actionPerformed (ActionEvent event) {

        String command = event.getActionCommand();
        JLabel nameFillLabel = new JLabel(); // not sure why put this here

            if(command.equals("recipientName")){
               JComboBox cb = (JComboBox)event.getSource();
              String combName = (String)cb.getSelectedItem();
              System.out.println(combName); // prints selected item to console
              nameFillLabel.setText(combName); // doesnt actually do anything
           }

}
***THIS IS FROM MessagerUI.java class***
private JComboBox recipientCombo = null;
private JLabel nameFillLabel = null;
...
recipientCombo = new JComboBox(names);
nameFillLabel = new JLabel();
...
recipientCombo = new JComboBox(names);
recipientCombo.setActionCommand("recipientName");
...

public void setActionListener(ActionListener sendActionEventsHere){
recipientCombo.addActionListener(sendActionEventsH ere);

}
I'm new to this and I think to problem may have something to do with me trying to update a JLabel thats contained within another class, if so how do I resolve this Issue, Any advice would be greatly appreciated.
nb. all java files are part of the messager package.

Thanks in Advance

Regards

Terry
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 5 2006
Added on Jan 8 2006
14 comments
318 views