JTextPane: insertComponent(Component c) : JTextPane « javax.swing « Java by API






JTextPane: insertComponent(Component c)

 
import java.awt.BorderLayout;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextPane;

public class PaneInsertionMethods {

  public static void main(String[] args) {

    final JTextPane pane = new JTextPane();

    pane.replaceSelection("text");
    pane.insertIcon(new ImageIcon("imageName.gif"));
    pane.insertComponent(new JButton("Click Me"));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(pane, BorderLayout.CENTER);
    frame.setSize(360, 180);
    frame.setVisible(true);
  }
}

           
         
  








Related examples in the same category

1.JTextPane: getDocument()
2.JTextPane: getStyledDocument()
3.JTextPane: insertIcon(Icon g)
4.JTextPane: replaceSelection(String content)
5.JTextPane: setCaretPosition(int position)
6.JTextPane.setCharacterAttributes(AttributeSet attr, boolean replace)
7.JTextPane: setFont(Font font)
8.JTextPane: setLogicalStyle(Style s)
9.JTextPane: setParagraphAttributes(AttributeSet attr, boolean replace)