HEEELLP - JEditorPane refuses to work

HELP ME PLEASE ,
I am using JEditorPane , using Swing 1.1
My problem is that whenever i use it in explorer
or netscape they give me the following error about plaf.metal.
I don't use anywhere in my program plaf....

in netscape :
java.lang.Error: can't load
javax.swing.plaf.metal.MetalLookAndFeel

  at java.lang.Throwable.<init>(Compiled Code)

  at java.lang.Error.<init>(Compiled Code)

  at javax.swing.UIManager.initializeDefaultLAF(Compiled Code)

  at javax.swing.UIManager.initialize(Compiled Code)

  at javax.swing.UIManager.maybeInitialize(Compiled Code)

  at javax.swing.UIManager.getUI(Compiled Code)

  at javax.swing.text.JTextComponent.updateUI(Compiled Code)

  at javax.swing.text.JTextComponent.<init>(Compiled Code)

  at javax.swing.JEditorPane.<init>(Compiled Code)

  at iCrad_Service_HTML_Response_Frame.<init>(Compiled Code)

  at iCrad_Service_HTML_Response_Frame.<init>(Compiled Code)

  at iCARD_Applet.main_logic(Compiled Code)

  at
iCARD_Service_Curr_Amount.serCurrAmountSubmitButton_ActionPerformed(Compiled
Code)

  at iCARD_Service_Curr_Amount$SymAction.actionPerformed(Compiled Code)

  at java.awt.Button.processActionEvent(Compiled Code)

  at java.awt.Button.processEvent(Compiled Code)

  at java.awt.Component.dispatchEventImpl(Compiled Code)

* at java.awt.Component.dispatchEvent(Compiled Code)

  at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled
Code)

  at java.awt.EventDispatchThread.run(Compiled Code)

  atnetscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(CompiledCode)


in Explorer the error is :

com.ms.security.SecurityExceptionEx[javax/swing/plaf/metal/DefaultMetalTheme.<init>]:
Unable to access system property: swing.plaf.metal.controlFont
 at com/ms/security/permissions/PropertyPermission.check
(PropertyPermission.java)
 at com/ms/security/PolicyEngine.shallowCheck (PolicyEngine.java)
 at com/ms/security/PolicyEngine.checkCallersPermission
(PolicyEngine.java)
 at com/ms/security/StandardSecurityManager.chk
(StandardSecurityManager.java)
 at com/ms/security/StandardSecurityManager.checkPropertyAccess
(StandardSecurityManager.java)
 at java/awt/Font.getFont (Font.java)
 at javax/swing/plaf/metal/DefaultMetalTheme.<init>
(DefaultMetalTheme.java:59)
 at javax/swing/plaf/metal/MetalLookAndFeel.createDefaultTheme
(MetalLookAndFeel.java:709)
 at javax/swing/plaf/metal/MetalLookAndFeel.getDefaults
(MetalLookAndFeel.java:714)
 at javax/swing/UIManager.setLookAndFeel (UIManager.java:363)
 at javax/swing/UIManager.setLookAndFeel (UIManager.java:383)
 at javax/swing/UIManager.initializeDefaultLAF (UIManager.java:848)
 at javax/swing/UIManager.initialize (UIManager.java:927)
 at javax/swing/UIManager.maybeInitialize (UIManager.java:945)
 at javax/swing/UIManager.getUI (UIManager.java:560)
 at javax/swing/text/JTextComponent.updateUI (JTextComponent.java:396)
 at javax/swing/text/JTextComponent.<init> (JTextComponent.java:356)
 at javax/swing/JEditorPane.<init> (JEditorPane.java:1193)
 at iCrad_Service_HTML_Response_Frame.<init>
(iCrad_Service_HTML_Response_Frame.java:140)
 at iCrad_Service_HTML_Response_Frame.<init>
(iCrad_Service_HTML_Response_Frame.java:75)
 at iCARD_Applet.main_logic (iCARD_Applet.java:101)
 at iCARD_Service_Curr_Amount.serCurrAmountSubmitButton_ActionPerformed
(iCARD_Service_Curr_Amount.java:170)
 at iCARD_Service_Curr_Amount$SymAction.actionPerformed
(iCARD_Service_Curr_Amount.java:161)
 at java/awt/Button.processActionEvent (Button.java)
 at java/awt/Button.processEvent (Button.java)
 at java/awt/Component.dispatchEventImpl (Component.java)
 at java/awt/Component.dispatchEvent (Component.java)
 at java/awt/EventDispatchThread.run (EventDispatchThread.java)

The relevant code is :

import javax.swing.JEditorPane;
and then
        javax.swing.JEditorPane JEditorPane1 = new javax.swing.JEditorPane();
        JEditorPane1.setContentType("text/html");
      JEditorPane1.setEditable(false);
      add(JEditorPane1);            JEditorPane1.setBackground(new java.awt.Color(94,206,192));
      JEditorPane1.setBounds(0,0,518,281);

Help any one???

LVL 1
uri22Asked:
Who is Participating?
 
OviConnect With a Mentor Commented:
I believe the solution is to load the Swing, when you load the applet, don't you ?

Explorer and Netscape doesn't know any Swing 1.1.1, so you must copy the archieve swingall.jar in the same directory with the applet and load into browser.
Something like this :

<APPLET NAME="Editor" archive="swingall.jar" CODE="Editor.class" WIDTH=800 HEIGHT=400>...params...</APPLET>

This is your first problem. Second you will see that you kannot use JEditorPane or JTextPane with HTML content in Netscape (this is my current problem and I need bad a solution) only in Explorer. I've create an HTML editor applet and is usable only in Internet Explorer in this moment. In NN is loading perfect but I cannot see the content or what I edit.
0
 
OviCommented:
About your question, MetalLookAndFeel is the default LookAndFeel for all components, so is normal that your applet try to load it.....
0
 
heyhey_Commented:
>> ... you kannot use JEditorPane or JTextPane

really ?
it works quite well with Java Plug-In 1.2.2
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
OviCommented:
To heyhey : if you say it's working, do you have some code ?

Like in my answear, I've made AN EDITOR which meens I use some buttons with associated actions (bold italic, center, ....) for editing HTML content. I've try with Java Plug-In 1.2 too, and is working of course, but only displaying the content with actions of buttons disabled.
SO ............!? I'm waiting - it begun to be much interesting this Swing discussion. (non english writer - so excuses for errors)
0
 
heyhey_Commented:
I implemented HTML editor sevreal days ago and it works fine with Java Plug-In 1.2.2 (note that it does NOT work with 1.2.1)
the code - is the simplest one - toolbar / several buttons that generte actions.

you can try to put the Stylepad Swing example into applet (it works fine too)
0
 
heyhey_Commented:
or post your code.
0
 
OviCommented:
Applet clsss :

import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.net.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import netscape.javascript.JSObject;

public class Editor extends JApplet {
  public static HTMLEditorKit kit;    
  public static HTMLDocument doc;//original doc este de tipul StyledDocument
  public static JTextPane pane;
  public static JLabel statusInfo;
  //*********************/
  public static JLabel progressLabel;
  public static JProgressBar progressBar;
  //*******************/
 
  public static String smartID;
  public static String langID;
  public static String infoObjID;
  public static String loadURL;
  public static String saveURL;
  public static String saveCGI;
  public static String valueReader;
  public static String infoObj;
  public static String time;
  public static String location;
  public static String numeric;
  public static String text;
  public static String smart;
  public static String template;
  public static String media;
      
  public static ButtonVector buttons;
 
  public static Image bird;
  public static Image cut;
  public static Image copy;
  public static Image paste;
  public static Image save;
  public static Image bold;
  public static Image italic;
  public static Image underline;
  public static Image left;
  public static Image right;
  public static Image center;
  public static Image justify;
  public static Image preview;
  public MediaTracker tracker;
      
  public static URL codeBase;
  public static AppletContext context;
          
  public static boolean WYSIWYG=false;
      
  public void init() {        
        //****************/
              EtchedBorder border = new EtchedBorder(EtchedBorder.LOWERED);
      JPanel panel = new JPanel();
      panel.setBorder(border);
      getContentPane().add(panel,BorderLayout.CENTER);
      panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

      JPanel progressPanel = new JPanel() {
        public Insets getInsets() {
            return new Insets(40,30,20,30);
        }
      };
     
      progressPanel.setLayout(new BoxLayout(progressPanel, BoxLayout.Y_AXIS));
      panel.add(Box.createGlue());
      panel.add(progressPanel);
      panel.add(Box.createGlue());
     
      Dimension labelSize = new Dimension(400, 20);
      progressLabel = new JLabel("Loading, please wait...");
      progressLabel.setAlignmentX(CENTER_ALIGNMENT);
      progressLabel.setMaximumSize(labelSize);
      progressLabel.setPreferredSize(labelSize);
      progressPanel.add(progressLabel);
      progressPanel.add(Box.createRigidArea(new Dimension(1,20)));

      progressBar = new JProgressBar();
      progressBar.setStringPainted(true);
      progressLabel.setLabelFor(progressBar);
      progressBar.setAlignmentX(CENTER_ALIGNMENT);
      progressBar.setMinimum(0);
      progressBar.setValue(0);
      progressBar.getAccessibleContext().setAccessibleName("Java2D loading progress");
      progressPanel.add(progressBar);
      getContentPane().add(panel,BorderLayout.CENTER);      
      validate();
      setVisible(true);
     
      progressBar.setMaximum(8);  
      progressLabel.setText("Loading context...");
      context = getAppletContext();
      context.showStatus("Loading.........");
      progressBar.setValue(progressBar.getValue() + 1);
//*****************/      
      progressLabel.setText("Loading parameters...");
     
      buttons = new ButtonVector(20, 10);//*******************************************/
      smartID = getParameter("SMARTID");
      langID = getParameter("LANGID");
      infoObjID = getParameter("INFOOBJID");
      loadURL = getParameter("LOAD");
      saveURL = getParameter("SAVEURL");
      saveCGI = getParameter("SAVECGI");
      valueReader = getParameter("VALUEREADER");
     
      infoObj = getParameter("INFO");
      time = getParameter("TIME");
      location = getParameter("LOCATION");
      numeric = getParameter("NUM");
      text = getParameter("TEXT");
      smart = getParameter("SMART");
      template = getParameter("TEMPLATE");
      media = getParameter("MEDIA");
     
      codeBase = getCodeBase();
      progressBar.setValue(progressBar.getValue() + 1);
     
      progressLabel.setText("Loading images...");
      tracker = new MediaTracker(this);
      cut = getImage(codeBase, "cut.gif");        
      tracker.addImage(cut, 0);
      try {
          tracker.waitForID(0);
      } catch(Exception x) {
          System.out.println("Eroare la tracker 0");
          return;
      }
      copy = getImage(codeBase, "copy.gif");
      tracker.addImage(copy, 1);
      try {
          tracker.waitForID(1);
      } catch(Exception x) {
          System.out.println("Eroare la tracker 1");
          return;
      }
      paste = getImage(codeBase, "paste.gif");
      tracker.addImage(paste, 2);        
      try {
          tracker.waitForID(2);
      } catch(Exception x) {
          System.out.println("Eroare la tracker 2");
          return;
      }
      bold = getImage(codeBase, "bold.gif");
      tracker.addImage(bold, 3);
      try {
          tracker.waitForID(3);
      } catch(Exception x) {
          System.out.println("Eroare la tracker 3");
          return;
      }
      italic = getImage(codeBase, "italic.gif");
      tracker.addImage(italic, 4);
      try {
          tracker.waitForID(4);
      } catch(Exception x) {
          System.out.println("Eroare la tracker 4");
          return;
      }
      underline = getImage(codeBase, "underline.gif");
      tracker.addImage(underline, 5);
      try {
          tracker.waitForID(5);
      } catch(Exception x) {
          System.out.println("Eroare la tracker 5");
          return;
      }
      left = getImage(codeBase, "left.gif");
      tracker.addImage(left, 6);
      try {
          tracker.waitForID(6);
      } catch(Exception x) {
          System.out.println("Eroare la tracker 6");
          return;
      }
      right = getImage(codeBase, "right.gif");
      tracker.addImage(right, 7);
      try {
          tracker.waitForID(7);
      } catch(Exception x) {
          System.out.println("Eroare la tracker 7");
          return;
      }
      center = getImage(codeBase, "center.gif");
      tracker.addImage(center, 8);
      try {
          tracker.waitForID(8);
      } catch(Exception x) {
          System.out.println("Eroare la tracker 8");
          return;
      }
      justify = getImage(codeBase, "justify.gif");
      tracker.addImage(justify, 9);
      try {
          tracker.waitForID(9);
      } catch(Exception x) {
          System.out.println("Eroare la tracker 9");
          return;
      }
      save = getImage(codeBase, "save.gif");
      tracker.addImage(save, 10);
      try {
          tracker.waitForID(10);
      } catch(Exception x) {
          System.out.println("Eroare la tracker 10");
          return;
      }
      bird = getImage(codeBase, "middle.gif");
      tracker.addImage(bird, 11);
      try {
          tracker.waitForID(11);
      } catch(Exception x) {
          System.out.println("Eroare la tracker 11");
          return;
      }
      preview = getImage(codeBase, "preview.gif");
      tracker.addImage(preview, 12);
      try {
          tracker.waitForID(12);
      } catch(Exception x) {
          System.out.println("Eroare la tracker 12");
          return;
      }
     
      boolean good = false;
      good = tracker.checkAll();
      good = tracker.isErrorAny();
      if (good)
          System.out.println("Error loading images !");
      else System.out.println("Images loaded !");        
     
      progressBar.setValue(progressBar.getValue() + 1);
     
      JRootPane rp = getRootPane();
      rp.putClientProperty("defeatSystemEventQueueCheck",Boolean.TRUE);

      // Setup Status Message Area
      statusInfo = new JLabel();            
     
      //Setup Text Pane */
      progressLabel.setText("Loading editor...");
      pane = new JTextPane();
      kit = new HTMLEditorKit();
      pane.setEditorKit(kit);
                  doc = (HTMLDocument)kit.createDefaultDocument();
                  
      //The Document class does not yet handle charset's properly*/
     
      doc.putProperty("IgnoreCharsetDirective",Boolean.TRUE);
      progressBar.setValue(progressBar.getValue() + 1);
                  //*****************/      
      progressLabel.setText("Setting content...");
      Loader l = new Loader();
      String content = l.result;
      pane.setText(content);
      pane.addMouseListener(new MouseEvents());
      pane.addKeyListener(new KeyEvents());
      doc = (HTMLDocument) pane.getDocument();
//      doc.addDocumentListener(new KeyEvents());
 //     pane.updateUI();        
      //Place in JScrollPane
      progressBar.setValue(progressBar.getValue() + 1);
                  //*****************/      
      progressLabel.setText("Scrolling...");
      JScrollPane sp = new JScrollPane (pane);
      sp.setBorder(border);//**************************BORDER***************************/
//                  sp.updateUI();
      progressBar.setValue(progressBar.getValue() + 1);
                  //*****************/      
         
      //Toolbar
      progressLabel.setText("Creating toolbar...");
      EditorToolBar toolbar = new EditorToolBar();
      toolbar.setBorder(border);//**************************BORDER***************************/
      progressBar.setValue(progressBar.getValue() + 1);
                  //*****************/      
                  
      //Setup Menus
      progressLabel.setText("Creating menu...");
      JMenuBar menuBar = new JMenuBar();
      setJMenuBar (menuBar);
      menuBar.setBorder(border);//**************************BORDER***************************/

      //Setup File Menu
      FileMenu file = new FileMenu ("File");
      file.setMnemonic('F');
      menuBar.add (file);

      //Setup Color Menu
      ColorMenu color = new ColorMenu("Color");
      color.setMnemonic('C');
      menuBar.add (color);

      // Setup Font Menu
      FontMenu myFont = new FontMenu("Font");
      myFont.setMnemonic('N');
      menuBar.add (myFont);

     
      // Setup Object Menu
      ObjectMenu object = new ObjectMenu("Objects");
      object.setMnemonic('J');
      menuBar.add(object);        
      progressBar.setValue(progressBar.getValue() + 1);
                  getContentPane().remove(panel);
      Container c = getContentPane();
      c.add (statusInfo, BorderLayout.SOUTH);
      c.add(sp, BorderLayout.CENTER);
                  sp.updateUI();
      c.add("North",toolbar);
      c.repaint();
                  //*****************/      
  }
   
  public static String showMSG() { System.out.println("12123421453253263457456");return "23"; }
 
  public static String copyFromHTML() {
    String copy = "";
    String msg[]=null;
    JSObject win=null;
    try {
          msg = new String[1];
          msg[0] = new String("");
          win = JSObject.getWindow(context.getApplet("Editor"));
    } catch (Exception e1) {
          System.out.println("Exceptie la FROM HTML : "+e1.toString());
    }
    try {
        copy = (win.call("getClip",msg)).toString();
    } catch (Exception e2) {
          System.out.println("Exceptie1 la FROM HTML : "+e2.toString());
    }        
      return copy;
  }
 
  public static void pasteToHTML(String text) {
    String msg[]=null;
    JSObject win=null;
    try {
          msg = new String[1];
          msg[0] = text;
          win = JSObject.getWindow(context.getApplet("Editor"));
    } catch (Exception e1) {
          System.out.println("Exceptie la TO HTML : "+e1.toString());
    }
    try {
        win.call("setClip",msg);
    } catch (Exception e2) {
          System.out.println("Exceptie1 la TO HTML : "+e2.toString());
    }        
  }
 
  public void destroy() {
    System.out.println("11111111111111111111111111111111111111111");
    FileMenu.doSaveCommand();
    System.out.println("11111111111111111111111111111111111111111");
  }
}

   
0
 
OviCommented:
Toolbar class :

import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;

public class EditorToolBar extends JToolBar {
            public static boolean alignmentEnabled = false;
    Preview prev;
    String[] toolKeys;
    public EditorToolBar() {
        createToolbar();
        prev = new Preview();
    }
   
    private Component createToolbar() {
          JTextField f;
          String s = new String("save - copy paste - bold italic underline - left center right - - - preview - - - - ");
          toolKeys = tokenize(s);
          for (int i = 0; i < toolKeys.length; i++) {
                if (toolKeys[i].equals("-")) {
                this.add(Box.createHorizontalStrut(5));
                } else {
                this.add(createTool(toolKeys[i]));
                }
          }
          
          f = new JTextField("InfoObj : "+Editor.infoObjID+"; Smart : "+
                Editor.smartID+"; Lang : "+Editor.langID,10) {//****************************/
            public float getAlignmentY() { return 0.5f; }
              };
          f.setRequestFocusEnabled(true);
          f.setMargin(new Insets(1,1,1,1));

          this.add(f);
          this.add(Box.createHorizontalGlue());
          return this;
    }
       
    protected String[] tokenize(String input) {
                Vector v = new Vector(10, 10);
                StringTokenizer t = new StringTokenizer(input);
                String cmd[];
                
                while (t.hasMoreTokens())
                      v.addElement(t.nextToken());
                cmd = new String[v.size()];
                for (int i = 0; i < cmd.length; i++)
                      cmd[i] = (String) v.elementAt(i);
                return cmd;
    }
       
    protected Component createTool(String key) {
                return createToolbarButton(key);
    }
     
    protected JButton createToolbarButton(String key) {    
        Image img = null;
        CustomButton b;
        for(int i = 0; i<toolKeys.length; i++) {
            if(key.equalsIgnoreCase("save")) img = Editor.save;
            else
            if(key.equalsIgnoreCase("copy")) img = Editor.copy;
            else
            if(key.equalsIgnoreCase("paste")) img = Editor.paste;
            else
            if(key.equalsIgnoreCase("bold")) img = Editor.bold;
            else
            if(key.equalsIgnoreCase("italic")) img = Editor.italic;
            else
            if(key.equalsIgnoreCase("underline")) img = Editor.underline;
            else
            if(key.equalsIgnoreCase("center")) img = Editor.center;
            else
            if(key.equalsIgnoreCase("left")) img = Editor.left;
            else
            if(key.equalsIgnoreCase("right")) img = Editor.right;
            else
            if(key.equalsIgnoreCase("preview")) img = Editor.preview;            
        }
            b = new CustomButton(img);
                b.setRequestFocusEnabled(false);
//                b.setMargin(new Insets(1,1,1,1));
          
            if(key.equalsIgnoreCase("save")) {
                        b.setActionCommand("doSaveCommand()");
                        String tip = "Save";
                        b.setToolTipText(tip);
                      b.addActionListener(new ActionListener() {
            public void actionPerformed (ActionEvent e) {
                  if(!KeyEvents.changes) {
                        KeyEvents.changes = true;
                    FileMenu.doSaveCommand();
                        KeyEvents.changes = false;
                  }
                  else FileMenu.doSaveCommand();
            }
                      });
            }
            else if(key.equalsIgnoreCase("copy")) {
                  b.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                              String imported = Editor.copyFromHTML();
                              Editor.pasteToHTML("<br>");
                              System.out.println("Imported : "+imported);
                              if(imported.equalsIgnoreCase("<br>")) breakReader("<br>");
                              else stringReader(imported);
                              
              if(!KeyEvents.changes) {
                KeyEvents.changes = true;
            FileMenu.doSaveCommand();
                KeyEvents.changes = false;
              }
              else FileMenu.doSaveCommand();
                }
                });
                  String tip = "Import from HTML";
                  b.setToolTipText(tip);
            }
            else if(key.equalsIgnoreCase("paste")) {
                  b.addActionListener(new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                    String selectedText = Editor.pane.getSelectedText();
                    if(selectedText != null) Editor.pasteToHTML(selectedText);
                      }
                      });
                  String tip = "Export to HTML";
                  b.setToolTipText(tip);
            }
            else if(key.equalsIgnoreCase("bold")) {
                  b.setActionCommand("new StyledEditorKit.BoldAction ()");
                b.addActionListener(new StyledEditorKit.BoldAction ());
                  String tip = "Bold";
                  b.setToolTipText(tip);
            }
            else if(key.equalsIgnoreCase("italic")) {
                  b.setActionCommand("new StyledEditorKit.ItalicAction ()");
                  b.addActionListener(new StyledEditorKit.ItalicAction ());
                  String tip = "Italic";
                  b.setToolTipText(tip);
            }
            else if(key.equalsIgnoreCase("underline")) {
                  b.setActionCommand("new StyledEditorKit.UnderlineAction ()");
                  b.addActionListener(new StyledEditorKit.UnderlineAction ());
                  String tip = "Underline";
                  b.setToolTipText(tip);
            }
            else if(key.equalsIgnoreCase("left")) {
                  b.setActionCommand ("new StyledEditorKit.AlignmentAction (\"Left Action\", 0)");                                    
                  b.addActionListener (new ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                                    String selectedText = new String(Editor.pane.getSelectedText());
            if(selectedText != null) doAlignmentAction(selectedText,"left");
                              }
                        });                                    
                  String tip = "Left Justify";
                  b.setToolTipText(tip);
            }
            else if(key.equalsIgnoreCase("center")) {
                  b.setActionCommand ("new StyledEditorKit.AlignmentAction (\"Center Action\", 1)");                                    
                  b.addActionListener (new ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                                    String selectedText = new String(Editor.pane.getSelectedText());
            if(selectedText != null) doAlignmentAction(selectedText,"center");
                              }
                        });                                    
                  String tip = "Center Justify";
                  b.setToolTipText(tip);
            }
            else if(key.equalsIgnoreCase("right")) {
                  b.setActionCommand ("new StyledEditorKit.AlignmentAction (\"Right Action\", 2)");                                    
                  b.addActionListener (new ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                                    String selectedText = new String(Editor.pane.getSelectedText());
            if(selectedText != null) doAlignmentAction(selectedText,"right");
                              }
                        });                                    
                  String tip = "Right Justify";
                  b.setToolTipText(tip);
            }
            else if(key.equalsIgnoreCase("preview")) {
                  b.addActionListener (new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                          Editor.WYSIWYG = ! Editor.WYSIWYG;
                          if(!Editor.buttons. isEmpty())
                        prev.makePreview();
                 }
                      });                                    
                  String tip = "Preview";
                  b.setToolTipText(tip);
            }       
          return b;
    }
   
    public void doAlignmentAction(String selection, String alignment) {
      HTMLEditorKit       kit = (HTMLEditorKit)Editor.pane.getEditorKit();
      int pos = Editor.pane.getSelectionStart();
                   Editor.pane.replaceSelection("");
                   alignmentEnabled = true;
                   
          try {
                     Reader r = new StringReader("<p align=\""+alignment+"\">"+selection+"</p>");
                     kit.read(r,(HTMLDocument)Editor.pane.getDocument(),pos);
                    if(!alignmentEnabled) {
                           Editor.pane.select(pos+selection.length(),pos+selection.length()+1);
                           Editor.pane.replaceSelection("");
                    }
                     Editor.pane.setCaretPosition(pos+4);
                     Editor.pane.updateUI();
                     Editor.pane.repaint();
               }catch(BadLocationException e1) {
                     System.out.println("Exceptie la offset !");
              }catch(IOException ex) {
                     System.out.println("Exceptie IO !");
               }
    }
   
    public void stringReader(String imported) {
                  int pos=Editor.pane.getCaretPosition();
              if(((HTMLDocument)Editor.pane.getDocument()).getLength()==4) {
                         Reader r;
                        HTMLEditorKit       kit = (HTMLEditorKit)Editor.pane.getEditorKit();
                        
                        try {
                                    r = new StringReader(imported);
                                    kit.read(r,(HTMLDocument)Editor.pane.getDocument(),3);
                                    Editor.pane.updateUI();
                                    pos = ((HTMLDocument) kit.createDefaultDocument()).getLength();
                                    Editor.pane.setCaretPosition(pos);
                                    System.out.println("Pozitie de insertie 1 : "+pos);
                        }catch(BadLocationException e1) {
                              System.out.println("EditorToolBar - Copy button exception 1 !!");
                        }catch(IOException ex) {
                              System.out.println("EditorToolBar - Copy button exception 2 !!");
                        }                            
              } else {
                         Reader r;
                        if(pos<3) {
                              Mesenger m = new Mesenger(new Frame(),"Error",true,"You can't insert text here !");
                              m.show();
                              return;
                        }
                        HTMLEditorKit       kit = (HTMLEditorKit)Editor.pane.getEditorKit();
                        try {
                                    r = new StringReader(imported);
                                    kit.read(r,(HTMLDocument)Editor.pane.getDocument(),pos);
                                    System.out.println("Pozitie : "+pos);
                                    if(pos==3) {
      //                                                            Editor.pane.select(pos-1,pos);
      //                                                            Editor.pane.replaceSelection("");
                                          Editor.pane.select(pos+imported.length(),pos+1+imported.length());
                                    }
                                    else {
                                          int length = ((HTMLDocument)Editor.pane.getDocument()).getLength();
                                          System.out.println("Pos : "+pos+" length : "+length);
                                          Editor.pane.select(pos,pos+1);
                                          String chr = Editor.pane.getSelectedText();
                                          if(imported.startsWith(chr)&(chr.equalsIgnoreCase(" "))==false)
                                                Editor.pane.replaceSelection(chr);
                                          else Editor.pane.replaceSelection("");
                                          Editor.pane.select(pos+imported.length(),pos+1+imported.length());
                                    }
                                    Editor.pane.replaceSelection("");
      //                                                      Editor.pane.setCaretPosition(pos+imported.length());
                                    Editor.pane.setCaretPosition(4);
                                    Editor.pane.updateUI();
                                    Editor.pane.setCaretColor(Color.black);
                        }catch(BadLocationException e1) {
                              System.out.println("EditorToolBar - Copy button exception 1 !!");
                        }catch(IOException ex) {
                              System.out.println("EditorToolBar - Copy button exception 2 !!");
                        }                            
              }
    }
   
    public void breakReader(String br) {
                   Reader r;
                  HTMLEditorKit       kit = (HTMLEditorKit)Editor.pane.getEditorKit();
                  int pos=Editor.pane.getCaretPosition();
                  System.out.println("Pos 1 : "+pos);

                  try {
                              r = new StringReader(br);
                              kit.read(r,(HTMLDocument)Editor.pane.getDocument(),pos);
                              
                      Editor.pane.select(pos,pos+1);
                      Editor.pane.replaceSelection(" ");
                      Editor.pane.select(pos+2,pos+3);
                      Editor.pane.replaceSelection("");
                      
                              Editor.pane.updateUI();
                              pos = ((HTMLDocument) kit.createDefaultDocument()).getLength();
                              Editor.pane.setCaretPosition(pos);
                              System.out.println("Pozitie de insertie 1 post : "+pos);
                  }catch(BadLocationException e1) {
                        System.out.println("EditorToolBar - Copy button exception 1 !!");
                  }catch(IOException ex) {
                        System.out.println("EditorToolBar - Copy button exception 2 !!");
                  }
    }    
}
0
 
OviCommented:
Can you provide some code too ?
0
 
heyhey_Commented:
I can't compile your code (you use too many additional classes).

if you contact me at heyhey_@iname.com, I can send you my *small) example - it may help you ... who knwos :)

best regards
  heyhey
0
 
OviCommented:
Can you provide some code too ?
0
All Courses

From novice to tech pro — start learning today.