Can a user-chosen image be inserted directly into a JEditorPane?

Posted by JIM on Stack Overflow See other posts from Stack Overflow or by JIM
Published on 2010-06-01T16:05:41Z Indexed on 2010/06/01 16:23 UTC
Read the original article Hit count: 303

Filed under:
|
|
|
|

What I am trying to do is open up a JFilechooser that filters jpeg,gif and png images, then gets the user's selection and inserts it into the JEditorPane. Can this be done? or am i attempting something impossible? Here is a sample of my program.(insert is a JMenuItem and mainText is a JEditorPane)

insert.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
    JFileChooser imageChooser = new JFileChooser();
      imageChooser.setFileFilter(new FileNameExtensionFilter("Image Format","jpg","jpeg","gif","png"));
                int choice = imageChooser.showOpenDialog(mainText);
                if (choice == JFileChooser.APPROVE_OPTION) {
                mainText.add(imageChooser.getSelectedFile());
                }
        }
    });

What i tried to do is use the add method, i know it's wrong but just to give you an idea of what i'm trying to do. Before you complain, i'm sorry about the code formatting, i don't really know all the conventions of what is considered good or bad style. Thank you very much.

© Stack Overflow or respective owner

Related posts about java

Related posts about html