How to access jtextPane in a different form?

邮差的信 提交于 2019-11-28 02:11:26
trashgod

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
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!