0

I want to scale and resize with mouse selected image, change selected image with corner point, and change scale picture in JTextPane as in Microsoft Word. This code just added image without change size in text editor but not have function propertes size picture. Please somebody help me with code:

JFileChooser jf=new JFileChooser();
// Show open dialog
int option=jf.showOpenDialog(this);
// If user chooses to insert..
if(option == JFileChooser.APPROVE_OPTION) {
    File file = jf.getSelectedFile();
    if(isImage(file)) {
        jTextPane1.insertIcon(new ImageIcon(file.getAbsolutePath()));
    }else
        // Show an error message, if not an image
        JOptionPane.showMessageDialog(this,"The file is not an image.", 
                "Not Image", JOptionPane.ERROR_MESSAGE);
}
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • 2
    Add the Icon to a JLabel and the label to a panel. Then you can use the `ComponentResizer` class found in [Resizing Components](https://tips4java.wordpress.com/2009/09/13/resizing-components/). It might also work if you add the label to a JTextPane, but I've never tried it. – camickr Oct 01 '17 at 17:57
  • Sorry, but i have tried your variant and the JTextPane don't add the JLabel. If you have the code, please share the code. – TheFnafException Oct 01 '17 at 18:04
  • `please share the code` - actually you are asking the question so you should be posting your code that demonstrates what you are doing. That is post a [mcve] that demonstrates the problem. So your `MCVE` will be a simple frame with a panel and a JTextPane. In the panel you will add the JLabel and in the text pane you will add the JLabel. A JTextPane supports an `insertComponent()` method so you should at least be able to display the label. – camickr Oct 01 '17 at 18:10
  • Another approach by the way would be to paint your own border directly to the JLabel that carries your image. Then, you should be able to resize your image with a mouseListener and mouseMotionListener. – Sharcoux Oct 02 '17 at 09:00

0 Answers0