Another good approach is to learn and use Action Classes. See How to Use Actions
Such a Action class encapsulates a unit of work ("login","print",...) and you simply attach it to one or more gui elements (JButton, JMenu, ...). If you use this concept, your application can grow more easily. Separating application logic, GUI and data is always a good idea.
A incomplete Example
public class ShowListAction extends AbstractAction {
JTextArea listArea;
YourListHandler listHandler;
public ShowListAction() {
this.putValue(Action.NAME,"Show List");
// this.putValue(Action.SMALL_ICON, yourIcon); // You can set various Properties for your Action...
this.setEnabled(enabled); // You can enable/disable the Action and hence any JButton connected to it ....
}
public void setListArea(JTextArea listArea) {
this.listArea = listArea;
}
public void setListHandler(YourListHandler listHandler) {
this.listHandler = listHandler;
}
public void actionPerformed(ActionEvent e) {
// Here comes the actual work
// list with data injected from another class which handles that
List<String> list = listHandler.getNamesList();
// output - correct
for (String s : list) {
listArea.append(s);
}
}
}
To use this, you need to create/fetch a instance of the Action within your view and attach it to e.g. a JButton with
yourButton.setAction(theAction)