Insert a picture into a JTextPane
In my notepad application, I am trying to add an image as if it were a JLabel into a JTextPane by clicking on a JMenuItem called Picture . private class Picture implements ActionListener { public void actionPerformed(ActionEvent event) { fc = new JFileChooser(); FileNameExtensionFilter picture = new FileNameExtensionFilter("JPEG files (*.jpg)", "jpg"); fc.setFileFilter(picture); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); if (fc.showDialog(Notepad.this, "Insert")!=JFileChooser.APPROVE_OPTION) return; filename = fc.getSelectedFile().getAbsolutePath(); // If no text is entered