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 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 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.
Thanks in Advance
Regards
Terry