I am developing an application where, when I select a value(file) from list it should be opened in jTextPane of a different form. I am using two panels one is mainpanel wher
Use Action to encapsulate the code that updates the text pane in order to display a given file. You can invoke the action from a ListSelectionListener added to your JList
. You can also use the action in a menu item or a toolbar button, as shown here. ImageApp is a related example.
For example, each instance of your action will need the target text pane and file:
class FileAction extends AbstractAction {
JTextPane target;
File file;
public FileAction(JTextPane target, File file) {
this.target = target;
this.file = file;
}
@Override
public void actionPerformed(ActionEvent e) {
// render file in target
}
}