How to access jtextPane in a different form?

后端 未结 1 1212
闹比i
闹比i 2020-12-07 04:43

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

相关标签:
1条回答
  • 2020-12-07 05:08

    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
        }
    }
    
    0 讨论(0)
提交回复
热议问题