Java JTextPane writeImage(final JTextPane jtPane, final ImageIcon msg)

Here you can find the source of writeImage(final JTextPane jtPane, final ImageIcon msg)

Description

write Image

License

Open Source License

Declaration

public static void writeImage(final JTextPane jtPane, final ImageIcon msg) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Image;

import javax.swing.ImageIcon;

import javax.swing.JTextPane;
import javax.swing.SwingUtilities;

public class Main {
    public static void writeImage(final JTextPane jtPane, final ImageIcon msg) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override//from   ww  w . j a va 2 s .  c  om
            public void run() {
                Image scaleImage = msg.getImage().getScaledInstance(75, 75, Image.SCALE_DEFAULT);
                msg.setImage(scaleImage);
                jtPane.insertIcon(msg);
            }
        });
    }

    public static void writeImage(final JTextPane jtPane, final ImageIcon msg, final int size) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                Image scaleImage = msg.getImage().getScaledInstance(size, size, Image.SCALE_DEFAULT);
                msg.setImage(scaleImage);
                jtPane.insertIcon(msg);
            }
        });
    }
}

Related

  1. setSelectionForeground(JTextPane textPane, Color color)
  2. setStyle(JTextPane textPane, int start, int length, String name)
  3. setStyle(JTextPane textPane, Style style)
  4. setTabs(int charactersPerTab, JTextPane textpane)
  5. setTextToPane(JTextPane textPane, String text, Color foregroundColor, Color backgroundColor)