import javax.swing.*;
import java.util.prefs.*;
import java.awt.event.*;
import javax.swing.text.*;

public class TextExemple implements ComponentListener,ActionListener {
  private static String LARGEUR = "LARGEUR";
  private static String HAUTEUR = "HAUTEUR";
  private JTextPane tp;
  private Preferences p;
  public void actionPerformed(ActionEvent e) { // pseudo-print
    System.out.println(tp.getText());
  }
  public void componentResized(ComponentEvent e) { // catch resize
    JFrame f = (JFrame)(e.getSource());
    p.putInt(LARGEUR,(int)(f.getSize().getWidth()));
    p.putInt(HAUTEUR,(int)(f.getSize().getHeight()));
  }
  public void componentMoved(ComponentEvent e) {
  }
  public void componentShown(ComponentEvent e) {
  }
  public void componentHidden(ComponentEvent e) {
  }
  public TextExemple() {
    JFrame f = new JFrame("Exemple");
    JScrollPane sp = new JScrollPane();
    tp = new JTextPane();
    tp.setContentType("text/html"); // Please, edit HTML content
    tp.setText("Bonjour<p><b>Au revoir</b>"); // Default HTML content
    sp.getViewport().add(tp);
    f.getContentPane().add(sp);

    JMenuBar mb = new JMenuBar();

    JMenu m2 = new JMenu("Fichier");
    mb.add(m2);
    JMenuItem mi = new JMenuItem("Voir"); // pseudo-print option
    m.add(mi);
    mi.addActionListener(this);

    JMenu m = new JMenu("Edition");
    mb.add(m);
    Action g = new StyledEditorKit.BoldAction(); // active current jtextpane bold mode
    m.add(g);


    //    f.pack(); // changed this to recover size from preferences file
    Preferences p = Preferences.userRoot().node("MonApp");
    int largeur = p.getInt(LARGEUR,100);
    int hauteur = p.getInt(HAUTEUR,100);

    f.setJMenuBar(mb);
    f.setSize(largeur,hauteur);
    f.setVisible(true);
    f.addComponentListener(this);
  }
  public static void main(String []a) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          new TextExemple();
        }
      }
      );
  }
}