How do I wire output to paneWithList
?
PaneWithList
has a listener on its JList
so that the selected row is output to the console. How can I direct that output to the JTextPane
on output?
Could PaneWithList
fire an event which Main
picks up? Would PropertyChangeSupport suffice?
Main.java:
package dur.bounceme.net;
import javax.swing.JTabbedPane;
public class Main {
private static JTabbedPane tabs;
private static PaneWithList paneWithList;
private static PaneWithTable paneWithTable;
private static Output output;
public static void main(String[] args) {
tabs = new javax.swing.JTabbedPane();
paneWithList = new PaneWithList();
paneWithTable = new PaneWithTable();
tabs.addTab("list", paneWithList);
tabs.addTab("table", paneWithTable);
tabs.addTab("output", output);
}
}
Here's an example using the observer pattern, also seen here, here and here. Note that it would also be possible to listen to the combo's model.
I'd be use JMenu with JMenuItems with contents layed by using CardLayout rather than very complicated JTabbedPane(s)
For my own reference, and for anyone using the Netbeans GUI builder, this works so far as it goes:
The PanelWithList class:
and Frame.java as a driver:
The key being that
panelWithList1PropertyChange
is the listener on 'panelWithList' itself.Because
PanelWithList.firePropertyChange("list", -1, 1);
cannot send Object nor String that I see, I'm not exactly sure how to get the value selected all the way from the JList up to the JFrame.Hmm, well the API says yes it can send Objects. Have to check that out.
I think it's necessary to get some info about the model which the JList is using up to the JFrame. However, doesn't that break MVC? Or maybe that's the wrong approach.