HTMLEditor

import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.RenderingHints;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.IOException;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JTextPane;import javax.swing.UIManager;import javax.swing.UnsupportedLookAndFeelException;import javax.swing.text.BadLocationException;import javax.swing.text.MutableAttributeSet;import javax.swing.text.SimpleAttributeSet;import javax.swing.text.html.CSS;import javax.swing.text.html.HTMLDocument;import javax.swing.text.html.HTMLEditorKit;import javax.swing.text.html.StyleSheet;public class AdditionalText extends JFrame implements ActionListener {          private static final int FRAME_WIDTH = 640;     private static final int FRAME_HEIGHT = 480;          private static final String FONT_FAMILY = "Courier New";     private static final String FONT_SIZE = "24";          private JButton leftAlign;     private JButton centerAlign;     private JButton rightAlign;     private JTextPane editor;     private JButton save;     private JButton dump;     private JButton format;     public AdditionalText() {          setTitle("Test Frame");                    JPanel topToolbar = new JPanel();          leftAlign = new JButton("Left");          centerAlign = new JButton("Center");          rightAlign = new JButton("Right");          ActionListener alignLeft = new HTMLEditorKit.AlignmentAction("alignLeft", 0);          ActionListener alignCenter = new HTMLEditorKit.AlignmentAction("alignCenter", 1);          ActionListener alignRight = new HTMLEditorKit.AlignmentAction("alignRight", 2);          leftAlign.addActionListener(alignLeft);          centerAlign.addActionListener(alignCenter);          rightAlign.addActionListener(alignRight);          topToolbar.add(leftAlign);          topToolbar.add(centerAlign);          topToolbar.add(rightAlign);                    editor = createEditor();                    JPanel bottomToolbar = new JPanel();          save = new JButton("Save");          save.addActionListener(this);          dump = new JButton("Dump");          dump.addActionListener(this);          format = new JButton("Format");          format.addActionListener(this);          bottomToolbar.add(save);          bottomToolbar.add(dump);          bottomToolbar.add(format);                    getContentPane().add(BorderLayout.NORTH, topToolbar);          getContentPane().add(BorderLayout.CENTER, editor);          getContentPane().add(BorderLayout.SOUTH, bottomToolbar);                    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);                    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();          setSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT));          setLocation((screenSize.width - FRAME_WIDTH) / 2, (screenSize.height - FRAME_HEIGHT) / 2);     }     private JTextPane createEditor() {          JTextPane editor = new JTextPane() {               public void paintComponent(Graphics g) {                    Graphics2D g2 = (Graphics2D) g;                    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);                    super.paintComponent(g2);               }          };                    editor.setEditorKit(new HTMLEditorKit());          HTMLDocument htmlDocument = (HTMLDocument) editor.getDocument();          MutableAttributeSet attr = new SimpleAttributeSet();          StyleSheet ss = htmlDocument.getStyleSheet();          ss.addCSSAttribute(attr, CSS.Attribute.FONT_FAMILY, FONT_FAMILY);          ss.addCSSAttribute(attr, CSS.Attribute.FONT_SIZE, FONT_SIZE);          editor.setCharacterAttributes(attr, false);                    try {               htmlDocument.insertString(0, "Sample Text 123 ����", attr);          } catch (BadLocationException e) {               e.printStackTrace();          }          return editor;     }     public void actionPerformed(ActionEvent e) {          HTMLDocument htmlDocument = (HTMLDocument) editor.getDocument();          if(e.getSource() == save) {               HTMLEditorKit kit = (HTMLEditorKit)editor.getEditorKitForContentType("text/html");               try {                    kit.write(System.out, htmlDocument, 0, htmlDocument.getLength());               } catch (IOException ex) {                    ex.printStackTrace();               } catch (BadLocationException ex) {                    ex.printStackTrace();               }          } else if(e.getSource() == dump) {               htmlDocument.dump(System.err);          } else if(e.getSource() == format) {               HTMLDocument doc = (HTMLDocument) editor.getDocument();               MutableAttributeSet attr = new SimpleAttributeSet();               StyleSheet ss = htmlDocument.getStyleSheet();               ss.addCSSAttribute(attr, CSS.Attribute.FONT_WEIGHT, "bold");               ss.addCSSAttribute(attr, CSS.Attribute.COLOR, "red");               int start = editor.getSelectionStart();               int end = editor.getSelectionEnd();               System.out.println("Start: " + start + "\tEnd: " + end);               doc.setCharacterAttributes(start, end, attr, false);          }     }          public static void main(String[] args) {          try {               UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());          } catch (ClassNotFoundException e) {               e.printStackTrace();          } catch (InstantiationException e) {               e.printStackTrace();          } catch (IllegalAccessException e) {               e.printStackTrace();          } catch (UnsupportedLookAndFeelException e) {               e.printStackTrace();          }          AdditionalText at = new AdditionalText();          at.show();     }     }
This code works, it is a small html editor:the problem is that if I write a line like this:
"Urgent:
buy the medicine"
the final html code return this line:
"Urgent:
buy the medicine".
It doesn't accept spaces and the use of Tab.
How can I make it accept them????
thank you.

This is the code written in a better way:
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.UIManager;
import javax.swing.text.AttributeSet;
import javax.swing.text.Element;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.html.CSS;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;
import javax.swing.Action;
* This is a very simple HTML Editor.
* It's purpose is to enter text and format it, if needed.
* The editor supports exporting the text to HTML.
public class AdditionalText extends JPanel implements ActionListener {
private static final int FRAME_WIDTH = 640;
private static final int FRAME_HEIGHT = 480;
private static final String FONT_FAMILY = "body {font-size: 13pt;}";
private static final String FONT_SIZE = "body {font-family: garamond;}";
private JTextPane editor;
private JButton save;
private JButton dump;
private JButton bold;
private JButton indent;
private JButton italic;
private JButton indent2;
private JButton underlined;
private JButton clearFormatting;
private Paziente paz;
private String iePath;
* Constructor for the <code>AdditionalText</code> editor.
* Most GUI components are defined, initialized and assembled here.
public AdditionalText(Paziente paz, String iePath) {
setName("HTML Editor Demo");
this.paz = paz;
this.iePath = iePath;
// Assemble the top toolbar:
JPanel topToolbar = new JPanel();
topToolbar.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 10));
JButton leftAlign = new JButton("Left");
JButton centerAlign = new JButton("Center");
JButton rightAlign = new JButton("Right");
leftAlign.addActionListener(new HTMLEditorKit.AlignmentAction(null, 0));
centerAlign.addActionListener(new HTMLEditorKit.AlignmentAction(null, 1));
rightAlign.addActionListener(new HTMLEditorKit.AlignmentAction(null, 2));
bold = new JButton("Bold");
indent = new JButton("Indent");
italic = new JButton("Italic");
underlined = new JButton("Underlined");
bold.addActionListener(this);
indent.addActionListener(this);
italic.addActionListener(this);
underlined.addActionListener(this);
clearFormatting = new JButton("Clear Formatting");
clearFormatting.addActionListener(this);
topToolbar.add(leftAlign);
topToolbar.add(centerAlign);
topToolbar.add(rightAlign);
topToolbar.add(bold);
topToolbar.add(indent);
topToolbar.add(italic);
topToolbar.add(underlined);
topToolbar.add(clearFormatting);
// Assemble the editor:
editor = createEditor();
JScrollPane editorScrollPane = new JScrollPane(editor);
// Assemble the bottom toolbar:
JPanel bottomToolbar = new JPanel();
bottomToolbar.setLayout(new FlowLayout(FlowLayout.CENTER, 50, 10));
save = new JButton("Save");
save.addActionListener(this);
dump = new JButton("Dump");
dump.addActionListener(this);
bottomToolbar.add(save);
bottomToolbar.add(dump);
this.setLayout(new BorderLayout());
this.add(topToolbar, BorderLayout.NORTH);
this.add(editorScrollPane, BorderLayout.CENTER);
this.add(bottomToolbar, BorderLayout.SOUTH);
// Display the window on the center of the screen:
// Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
// setSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
// setLocation((screenSize.width - FRAME_WIDTH) / 2, (screenSize.height - FRAME_HEIGHT) / 2);
* Creation and set up of an simple HTML editor.
* @return the created editor.
private JTextPane createEditor() {
JTextPane editor = new JTextPane() {
// Improve readability of the text inside the editor:
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
super.paintComponent(g2);
editor.setEditorKit(new HTMLEditorKit());
// Set the default style for the document:
HTMLDocument htmlDocument = (HTMLDocument)editor.getDocument();
MutableAttributeSet mutuableAttributeSet = new SimpleAttributeSet();
StyleSheet styleSheet = htmlDocument.getStyleSheet();
styleSheet.addRule(FONT_FAMILY);
styleSheet.addRule(FONT_SIZE);
// Insert a sample text into the editor for testing purpose:
try {
Element root = htmlDocument.getDefaultRootElement();
Element element = root.getElement(0).getElement(0);
htmlDocument.insertAfterEnd(element, "<p>esempio</p>");//SAMPLE_TEXT1+SAMPLE_TEXT2+SAMPLE_TEXT3);
} catch (Exception e) {
e.printStackTrace();
return editor;
* Handling the actions associated to the buttons "Save", "Dump", "Format Text"
* and "Clear Formatting".
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
public void actionPerformed(ActionEvent e) {
HTMLDocument htmlDocument = (HTMLDocument) editor.getDocument();
if (e.getSource() == save) {
HTMLEditorKit kit = (HTMLEditorKit) editor.getEditorKitForContentType("text/html");
try {
// Output the document object to HTML text:
kit.write(System.out, htmlDocument, 0, htmlDocument.getLength());
} catch (Exception ex) {
ex.printStackTrace();
} else if (e.getSource() == dump) {
// Output the document object to a XML like text representation:
htmlDocument.dump(System.err);
} else if (e.getSource() == bold) {
// Apply formatting to the selected text:
int start = editor.getSelectionStart();
int end = editor.getSelectionEnd();
MutableAttributeSet attr = new SimpleAttributeSet();
StyleSheet ss = htmlDocument.getStyleSheet();
ss.addCSSAttribute(attr, CSS.Attribute.FONT_WEIGHT, "bold");
ss.addCSSAttribute(attr, CSS.Attribute.COLOR, "blue");
htmlDocument.setCharacterAttributes(start, end - start, attr, false);
} else if (e.getSource() == indent) {
// Apply formatting to the selected text:
int start = editor.getSelectionStart();
int end = editor.getSelectionEnd();
MutableAttributeSet attr = new SimpleAttributeSet();
StyleSheet ss = htmlDocument.getStyleSheet();
ss.addCSSAttribute(attr, CSS.Attribute.MARGIN_LEFT, "3em");
htmlDocument.setCharacterAttributes(start, end - start, attr, false);
} else if (e.getSource() == underlined) {
// Apply formatting to the selected text:
int start = editor.getSelectionStart();
int end = editor.getSelectionEnd();
MutableAttributeSet attr = new SimpleAttributeSet();
StyleSheet ss = htmlDocument.getStyleSheet();
ss.addCSSAttribute(attr, CSS.Attribute.TEXT_DECORATION, "underline");
htmlDocument.setCharacterAttributes(start, end - start, attr, false);
} else if (e.getSource() == italic) {
// Apply formatting to the selected text:
int start = editor.getSelectionStart();
int end = editor.getSelectionEnd();
MutableAttributeSet attr = new SimpleAttributeSet();
StyleSheet ss = htmlDocument.getStyleSheet();
ss.addCSSAttribute(attr, CSS.Attribute.FONT_STYLE, "italic");
htmlDocument.setCharacterAttributes(start, end - start, attr, false);
} else if (e.getSource() == clearFormatting) {
// Remove formatting of the selected text:
int start = editor.getSelectionStart();
int end = editor.getSelectionEnd();
Element element = htmlDocument.getCharacterElement(start);
AttributeSet attributeSet = element.getAttributes();
StyleSheet styleSheet = htmlDocument.getStyleSheet();
attributeSet = styleSheet.removeAttribute(attributeSet, CSS.Attribute.FONT_WEIGHT);
attributeSet = styleSheet.removeAttribute(attributeSet, CSS.Attribute.COLOR);
htmlDocument.setCharacterAttributes(start, end - start, attributeSet, true);

Similar Messages

  • HTMLEDITOR DOESN'T WORK ON NETSCAPE!!!

    Hi all,
    I am using Netscape4.74 as my browser, an applet which uses some swing components and HtmlEditor kit components. I have archived all required class(swing classes and HtmlEditor class) in a jar and supplying it to my applet through archive attribute.
    It is working perfectly fine on a Internet Explorer5.50, but if I try the same on Netscape4.74 all the swing components appear without any problem but the problem is with these HtmlEditor stuffs. I am trying to display a simple html code(with html,head,body and my text enclosed within p tag and closing tags for all these) but that doesn't appear atall.
    I thought I have done some mistake in my code, so I tried to run an applet from the site
    http://sunsite.kth.se/javafaq/slides/OReillyJava2000/webclient/08.html
    to my suprise even this applet doesn't work on a Netscape4.74. They are sending complete swing jar still it doesn't work.
    Can You guys tell me what might be the problem, should I include some other plug-ins..or something else.
    Please help me, I have tried alot on this. Direct me to any link where I can find some information on this.
    Thanks in advance
    Jagadish

    Hi jbrasseur,
    Thanx alot for replying back.
    But I have downloaded that too, And have started the plugin.
    Would you mind telling me what did you do with that plug-in?? Would you mind giving me some more information about what you did.
    Please reply back,
    Thank You
    Jagadish

  • Sync Text alignment in HTMLEditor and a PDF generated using FOP

    Hi,
    How to sync text alignment in HTMLEditor and a PDF generated using FOP ?
    I tried setting the dimensions of HTMLEditor and PDF in pixels by calculating the size in Pixels for A4 paper size with a particular dpi value.
    Have done the font settings as well. The problem is I see uneven line cuts in the PDF as compared to HTMLEditor.
    Thanks.

    It's not a realistic expectation. You are expecting the PDF produced by whoever provided your FOP implementation to observe exactly the same typographical rules as HTMLEditor. Basically it won't, and there is no way to enforce it. Line breaking/hyphenation/word spacing algorithms can be of great complexity. You are expecting two systems that aren't specified to agree, to agree.

  • HTMLEditor : how to display Source and parsed content ?

    Hi everyone,
    I'm currently working on a HTMLEditor that consists of
    one tabbed pane and a tool bar.
    My tabbed pane has two associated panes :
    Editor ( a JTextPane)
    Source ( a JEditorPane)
    I already know how to bind my JTextPane to a HTMLKit and bind the HTMLKit to a HTMLDocument.
    When I type text in my JTextPane it appears just as it should in a web browser (it's already parsed).
    What I would like to do now is to display the source of
    the HTML document when I click on the source Tab.
    I already know how to write this source into a file from the JTextPane, but instad of wirting the source into a file I would like to write it in the JEditorPane.
    Is this a View issue ? Do I have to plug a different View to my Editor so it displays the HTMLDocument ? And if it's so, how do I do ? Isn't there any standard view ready to this ? To display HTML Source code from an existing HTMLDocument ?
    Thanxs for the help

    Here's some working code snippet to illustrate what I meant:
    assuming editorPane being a usual JEditorPane/JTextPane used to do the editing and sourcePane a JEditorPane to show the source (text + tags) then create the sourcePane with:
    private JEditorPane createSourcePane() {
         JEditorPane sourcePane = new JEditorPane();
         sourcePane.setEditable(false);
         sourcePane.setContentType("text/plain");
         return sourcePane;
    }to show the (complete) source after some edit:
    private void showTree() {
         if ((sourcePane == null) || (editorPane == null)) return;
         Reader reader = null;
         try {
              char[] chars = getSource();
              D.ebug("got array " + chars.length);
              reader = new CharArrayReader(chars);
              Document doc = new PlainDocument();
              sourcePane.getEditorKit().read(reader, doc, 0);
              sourcePane.setDocument(doc);
         } catch (Exception ex) {
              ex.printStackTrace();
         } finally {
              try {
                reader.close();
              } catch (IOException ioEx) {
                   ioEx.printStackTrace();
    private char[] getSource() {
         CharArrayWriter writer = null;
         try {
              writer = new CharArrayWriter();
              editorPane.getEditorKit().write(writer, editorPane.getDocument(), 0, editorPane.getDocument().getLength());
              return writer.toCharArray();
         } catch (Exception ex) {
              ex.printStackTrace();
         } finally {
              try {
                   writer.close();
              } catch (Exception ioEx) {
                   ioEx.printStackTrace();
         return null;
    }simply setting the contentType of the sourcePane to text/plain and then do a
    sourcePane.setDocument(editorPane.getDocument()) does show the unformatted text of the html without the tags.
    Greetings
    Jeanette

  • Font color issue with inserted HTML content in JTextPane (HTMLEditor)

    Hi everyone,
    I have a very serious issue with the HTMLEditor I'm developping. This editor is a little bit special since it is intended to edit blocks of HTML content that are loaded when the editor is initialized.
    You can in fact decide to keep this loaded HTML content or start a new HTML document from scratch. Alright, now my issue is the following :
    When text is loaded, it's properly rendered. I have a functionality which let's you see the HTML code from the HTML document used in the editor, so I can check and see if code is correct, and yes, it's correct.
    The problem is that when I try to change the color attribute of some text on my loaded content, nothing happens ! I don't know what's the matter with this bug, I only have it with the color attribute, with every other attribute everything's fine (font, size, etc.)
    The funny thing is that, after I change another attribute for loaded content, like font family, then changing color attribute funcionnality starts to work again !
    I've also noticed that I don't have any of these problems when I start my HTMLDocument from scratch (when I create a new HTML document and start typing text).
    Another weird thing, is that I have a feed-back feature in my editor which reflects attributes for text over which the caret is positionned. For example, if you put caret over red text, the color combo box displays a red value, you know, just like in MS Word. Well, with my loaded content if I have a red text color and I decide to put it in green, the color combo box displays the green value when I click over text for which I have changed color, but in my JTextPane it's still red !! And when I try to see the HTML code generated nothing has changed, everything is still red !
    There is something really strange here, this means that when I get the attributes of the loaded text from the HTMLDocument, color appears to be green, but when it gets rendered in the JTextPane it's still red and when it gets anlyzed to produce the corresponding HTML code, these changed attributes are not taken into account.
    But the most weird thing above all, is that I don't have this bug everytime, sometimes I start my HTML editor applet and it works fine, and some other times this color issue is bakc there. Is this a known bug for Swing API or not ?
    =============
    This is more or less my technique :
    //I declare a global reference to my HTMLDocument
    HTMLDocument _docHTMLDoc;
    //Create a JTextPane
    JTextPane _tpaEditor = new JTextPane( );
    //Set type content to automatically select HTMLEditorKit
    _tpaEditor.setContentType("text/html");
    //Get a referene to its HTMLEditorKit
    HTMLEditorKit _kitHTMLEditor = (HTMLEditorKit) _tpaEditor.getEditorKit( );
    //I then have a function to create new documents
    void newDocument(){
      _docHTMLDoc = (HTMLDocument) _kitHTMLEditor.createDefaultDocument();
      _tpaEditor.setDocument(_docHTMLDoc);
       //I do other stuff wich are not important to be shown here
    //I then have another function to load content
    void loadContent(){
       //I get content from a HashMap I initialized when I started my applet
       String strContent = (String)_mapInitParameters.get("html_content");
       //I set content for my editor
       _tpaEditor.setText(strContent);
    //Notice.. I have tried many other ways to load this text : via HTMLEditorKit and its insertHTML method, I
    //have also tried to store this content in some reader and make HTMLEditorKit read it... and nothing,
    // I always get the bug
    //To change color it goes like this :
    JComboBox _cboColor = new JComboBox();
    //I correctly initialize this combo with colors
    //then I do something like this
    ActionListener _lst = new ActionListener(){
       public void actionPeformed(ActionEvent e){
          Color colSel = (Color) _cboColor.getSelectedItem();
          MutableAttributeSet mas = new SimpleAttributeSet();
          StyleConstants.setForeground(mas,colSel);
          setAttributeSet(mas);
    _cboColor.addActionListener(_lst);
    //Set Attributes goes something like this
    private void setAttributeSet(javax.swing.text.AttributeSet atrAttributeSet) {       
            //Get current 'End' and 'Start' positions
            int intCurrPosStart = _tpaEditor.getSelectionStart();
            int intCurrPosEnd = _tpaEditor.getSelectionEnd();
            if(intCurrPosStart != intCurrPosEnd){
                //Apply attributes to selection
                _docHTMLDoc.setCharacterAttributes(intCurrPosStart,intCurrPosEnd - intCurrPosStart,atrAttributeSet,false);
            else{
                //No selection : apply attributes to further typed text
                MutableAttributeSet atrInputAttributes = _kitHTMLEditor.getInputAttributes();
                atrInputAttributes.addAttributes(atrAttributeSet);

    hi, friend!
    try this:
    void setAttributeToText(JTextPane pane, int start, int end, Color color) {
    MutableAttributeSet new_att = new SimpleAttributeSet();
    StyleConstants.setForeground(new_att,color);
    HTMLDocument doc=(HTMLDocument)pane.getDocument();
    doc.setCharacterAttributes(start,end,new_att,false);
    It works fine in my Application, hope will work in yours, too.
    good luck.

  • Displaying Unicode (Kannada) characters in HTMLEditor/ TextArea

    Dear All,
    I am newbie to JavaFX and also to java desktop ui applications. Was trying to create a simple text editor in Kannada but was unable to display the Kannada text in the editor. However, I gave the stage a Kannada title and that was displayed. Is there anything special I need to do (like setting encoding or something) to have the editor display Kannada fonts? Please help. Here is the code that I have written:
    Group root = new Group();
    Scene scene = new Scene(root, 800, 600, Color.WHITE);
    primaryStage.setScene(scene);
    primaryStage.setTitle("ಅಚ್ಚು ಕಲಿ"); // This text is displayed in the title of the window
    HTMLEditor editor = new HTMLEditor();
    editor.setHtmlText("ಇಲ್ಲಿ ಬರೆಯಿರಿ"); // This text shows up as boxes
    root.getChildren().add(editor);
    primaryStage.show();
    Please help!
    Thanks,
    Sandeep.

    By experimenting and some searching through the net I figured out that you need to set the right font. Kannada can be displayed using Tunga font on windows. But neither HTMLEditor nor TextArea has a setFont() method. Instead I tried with Text.
    text.setFont(Font.font("Tunga", 25.0));
    This worked partially. For example, if I try printing the character 'ಲಿ' its two component characters 'ಲ ಿ' are getting printed. They are not joining to form one single character 'ಲಿ'. Kannada like other Indic scripts is a complex layout script and I figured out from this post that complex layouts are not yet supported.
    Re: Urdu language support in Javafx UI Controls
    Unfortunately I cant use javafx for my purpose :-((

  • How to add and use custom javafx2.2.3 HTMLEditor skin .properties file

    Hallo, I'd like to know if there is a (not necessary officially supported) way to use custom HTMLEditorSkin.properties in javafx 2.2.3.
    The original file/files are located in jfxrt com/sun/javafx/scene/web/skinIf there is no way to do that, can something else be done to change languege strings and icons for HTMLEditor?

    See this thread.
    Error Installing Groupware Portlets for WLP 10.3.2
    Brad

  • HTMLEditor not displaying selection

    Hiya! In an HTMLEditor that I'm working with, I allow the user to input text, select some/all of the text, and then change some formatting of the text (such as text size). The goal is to have the same piece of text selected after the format has been modified. So, the idea, along with my code, is pretty simple...
    (parent is the name of my HTMLEditorKit)
    String s = parent.getSelectedText();
    int caretStart = parent.getSelectionStart();
    int caretEnd = parent.getSelectionEnd();
    SimpleAttributeSet attribs = new SimpleAttributeSet();
    attribs.addAttribute("size", "+2");
    insertCode(HTML.Tag.FONT, attribs);
    parent.select(caretStart, caretEnd);
    parent.requestFocus();The problem is that after the text is changed, the parent.select(int, int) statement is not apparent. It works but just isn't a visible selection. What would I need to change to make it visible?
    -kwbrads

    Okay, I feel stupid for having just realized this, but for some reason my HTMLEditor isn't receiving the focus. Even though I specifically call the requestFocus() function... this must be because the way I am changing the formatting is by using a JPopupMenu inside a JTabbedPane, so maybe the JPopupMenu still retains the focus even though it is no longer visible.
    So... grr. Is there a way to make sure that when the popup menu goes non-visible it transfers the focus back to the correct pane? Is this too general of a question? I would've thought the requestFocus() that I called would have done it, but I guess not...
    -kwbrads

  • Displaying Flash movie in JEditorPane -- HTMLEditor

    Hi,
    I am writing an HTMLEditor using Applet. I am using JEditorPane/JTextPane for editing the HTML page. I am displaying an HTML page using the setPage method of JEditorPane/JTextPane. But, I am not able to see the flash movie which is embeded in the HTML page.
    Did anybody try this? I saw a lot of questions regarding HTMLEditor using Applet, but haven't seen one regarding the flash movie display.
    I saw JMF(Java Media Framework), but it can be used only if we want to embed flash in java(eg:Applet,Frame) directly. Seems like JMF will not solve my problem.
    Can someone help me out.
    Thanx in advance.
    Satish K Kumar

    I'm trying to design a widget for adobe AIR that would
    display an external webpage in one of it's windows. What program do
    you suggest I use?

  • I can't type bold-text in Japanese using HTMLEditor

    I am using JAVAFX to develop tool.
    While I create a screen of HTMLEditor in eclipse,
    It does not be "bold-text" when I enter Japanese, although I'm pressing the "Bold-button".
    At this moment, I'm choosing the font, MS Gothic, PGothic,
    it does not be bold either.
    I can type English in bold-text, but I can't type bold-text in Japanese.
    I appreciate if you tell me the reason why this thing happens.
    Is this kind of a "bug" in the HTMLEditor?
    Or somekind of setting problem?
    http://bitwalk.sitemix.jp/java_javafx_HTMLEditor.php
    Thank you for your cooperation.

    Log a bug report against the runtime project at: http://javafx-jira.kenai.com

  • How to Make CDHTMLDialog based HTMLEditor

    Hello,
    I want to make HtmlEditor Having MFC Editor and backend Skin is based on Html using CDHTMLDialog. That is an area is left for Editor that will use either CHTMLEditCtrl or CHtmlView for editing and skin is based on CDHTMLDialog Html.
    Is there any way to do it or any example will be appreciated.
    Please Help.
    Thank You. 

    CDHTMLDialog's inner webbrowser control takes up the whole client area. There is no space left for a CHTMLEditCtrl or CHtmlView (which expects its parent to be a CFrameWnd, not sure why you think putting it in a dialog is a good idea). If you want to support
    editing in CDHTMLDialog you have to enable from HTML (e.g. put a
    <div id="example" contenteditable="true">
    somewhere in the HTML resource used by CDHTMLDialog. A more sophisticated HTML editor would involve lots of Javascript but then there are many HTML editors on the market (like the one used on this forum). 
    Visual C++ MVP

  • TinyMCE / Mojarra Scales HtmlEditor +  JSF RI problems

    I am trying to add a Rich Text editor on my project, so far I've tried TinyMCE and Mojarra Scales HtmlEditor without complete success, both are being rendered but after that I have the following problems:
    TinyMCE:
    Is being displayed but when I click on the "Save" button to execute the action and go to the following page the tinyMCE editor on the second page is not being rendered, and if click on the "Back" button to go back to the first page then the tinyMCE editor on that page is not being rendered anymore.
    MojarraScales"
    The component is being rendered but when I click on the "Save" button to go to the next page all it does is reload the first page, so I'm not able to access the second page.
    Thanks in advance

    Hi Raymond, yes the "Save" button use to work with an ordinary textarea. I added the <h:messages/> tag and I'm not getting anything and Firebug is not reporting any error, here is the code on the first page:
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
         xmlns:ui="http://java.sun.com/jsf/facelets"
         xmlns:h="http://java.sun.com/jsf/html"
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:a4j="http://richfaces.org/a4j"
         xmlns:rich="http://richfaces.org/rich" version="2.0"
         xmlns:sc="http://java.sun.com/mojarra/scales">
         <ui:composition template="/templates/member_t.jspx">
              <f:loadBundle basename="resources/messages" var="msg" />
              <ui:define name="body">
                   <f:view contentType="text/html">
                   <head>
                        <sc:links />
                   </head>
                        <h:form id="descForm">
                             <h:panelGrid columns="1">
                                  <h:outputText value="#{msg.newCntTitle}" />
                                  <h:inputText size="68" />
                                  <h:outputText value="#{msg.newDescTitle}" />                              
                                  <sc:htmlEditor id="one" width="500px" height="300px" value="#{ArticleBean.description}" />   
                                  <h:panelGroup>
                                       <h:commandButton value="#{msg.newBtnBack}" disabled="true" />
                                       <h:commandButton value="#{msg.newBtnCont}"
                                            action="#{ArticleBean.saveNewArt}" />
                                  </h:panelGroup>
                             </h:panelGrid>
                        </h:form>     
    <h:messages/>          
                   </f:view>
              </ui:define>
         </ui:composition>
    </jsp:root>I followed the configuration on Mojarra's website, first I added this jsftemplating-base-1.2-SNAPSHOT.jar and the dependency to Maven, and then I added this code to my faces-config.xml
         <lifecycle>
              <phase-listener>
                   com.sun.jsftemplating.util.fileStreamer.FileStreamerPhaseListener
              </phase-listener>
         </lifecycle>If you have any suggestions please let me know

  • HTMLEditor Spell Checking and Undo (javafx)

    Hi There,
    Is it possible to plug a spell checker to an HTMLEditor?
    Could we also activate an Undo feature on it? HTMLEditor has no TextProperty, so implementing the Undo is not straight forward..
    Do we have a way to set the caret position in the HTMLEditor?
    Many thanks for your help.
    Regards,
    Y

    Editing the Spelling Dictionary should be included in the '''Tools''' menu.
    This feature needs to be added on the next update for FF4.

  • HTMLEditor with Javascript

    Hi,
    I'm working on an html renderer with an advanced syntax editor.
    To achieve that I used an HTMLEditor and TextArea components and aggregated them in a TabPane
    Initially a default html is loaded, note that this html contains some javascript code to print the date
    When I click on the tab containing the TextArea, I get the text from the HTMLEditor using getHtmlText() and set it in theTextArea
    and When I click on the tab containing the HTMLEditor, I took the text from the TextArea and set it in the HTMLEditor using setHtmlText(...)When setting the text of the TextArea from the getHtmlText() I noticed that the original HTML has changed. It has a new line which is the rendered javascript value, in my case the date is displayed twice.
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    import javafx.application.Platform;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.embed.swing.JFXPanel;
    import javafx.geometry.Side;
    import javafx.scene.Scene;
    import javafx.scene.control.Tab;
    import javafx.scene.control.TabPane;
    import javafx.scene.control.TextArea;
    import javafx.scene.web.HTMLEditor;
    public class CustomHTMlEditorSample extends JFrame {
        private final String INITIAL_TEXT = "<html>"+
                 "<script type=\"text/javascript\">"+
                 "document.write(\"<p>\"+ Date()+\"</p>\");"+
                 "</script>"+
                 "<body>HTML Text" +
                 "<" +
                 "script type=\"text/javascript\">document.write(\"<p>\" + Date() + \"</p>\");</script>" +
                "</body></html>";
        public CustomHTMlEditorSample() {
            final JFXPanel fxPanel = new JFXPanel();
            add(fxPanel);
            setSize(400, 400);
            setVisible(true);
            Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        initFX(fxPanel);
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        new CustomHTMlEditorSample();
        private void initFX(JFXPanel fxPanel) {
            final HTMLEditor htmlEditor = new HTMLEditor();
            final TabPane tabPane = new TabPane();
            tabPane.setSide(Side.BOTTOM);
            Tab viewTab = new Tab();
            viewTab.setClosable(false);
            viewTab.setText("Renderer");
            viewTab.setContent(htmlEditor);
            tabPane.getTabs().add(0, viewTab);
            Tab htmlTab = new Tab();
            htmlTab.setClosable(false);
            htmlTab.setText("Editor");
            final TextArea textArea = new TextArea();
            textArea.focusedProperty().addListener(new ChangeListener<Boolean>() {
                    @Override
                    public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
                          if(!newValue) {
                              htmlEditor.setHtmlText(textArea.getText());
                         } else {
                              textArea.setText(htmlEditor.getHtmlText());
            htmlEditor.focusedProperty().addListener(new ChangeListener<Boolean>() {
                   @Override
                   public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
                        if(!newValue) {
                          textArea.setText(htmlEditor.getHtmlText());
            htmlEditor.setHtmlText(INITIAL_TEXT);
            textArea.setText(INITIAL_TEXT);
            htmlTab.setContent(textArea);
            tabPane.getTabs().add(1, htmlTab);
            // This method is invoked on the JavaFX thread
            Scene scene = new Scene(tabPane);
            fxPanel.setScene(scene);
    }Thanks

    Does someone has an idea?

  • WebView / HTMLEditor - caret position and selected content

    Hey :)
    Is it possible to get the caret position and the selected content in the HTMLEditor / WebView? How?
    Thanks in advance.

    Use JavaScript methods. For example:
    http://stackoverflow.com/questions/9370197/caret-position-cross-browser
    http://stackoverflow.com/questions/6129006/get-the-raw-html-of-selected-content-using-javascript
    Use the Java\JavaScript bridge if you want the result in Java:
    http://docs.oracle.com/javafx/2/webview/jfxpub-webview.htm

  • HTMLEditor lost control after setHtmlText twice

    I setup applicaton using javafx.scene.web.HTMLEditor.
    I init HTMLEditor ,setHtmlText ,and run fine.
    After I invoke setHtmlText twice or more , HTMLEditor lost control , HTMLEditor can no be edit any more.
    and I notice no document about HTMLEditor at JavaFx 2.0 release notes, what is the matter.
    plz help.
    Edited by: user2411627 on 2011-8-3 下午8:12

    Hi Darryl ,
    Here is the SSCCE for setHtmlText ,run up , HTMLEditor is edtiable, push Button "Set HTML" HTMLEditor lost control ,can not edit any more.
    run on JDK 1.6.0_17
    javafx_sdk-2_0-beta-b37-windows-i586-19_jul_2011.zip
    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.VBox;
    import javafx.scene.web.HTMLEditor;
    import javafx.stage.Stage;
    public class testhtmleditor extends Application {
         HTMLEditor htmlview = null;
         public void start(Stage stage) {
              stage.setTitle("test HTMLEditor");
              stage.setResizable(false);
              Scene scene = new Scene(new Group(), 600, 400);
              stage.setScene(scene);
              Group root = new Group();
              scene.setRoot(root);
              VBox vbox = new VBox();
              Button btn = new Button("Set HTML");
              btn.setOnMouseReleased(new EventHandler<MouseEvent>() {
                   public void handle(MouseEvent me) {
                        htmlview.setHtmlText("<HTML> <HEAD>  "
                                  + " <TITLE> HTMLEditor</TITLE> "
                                  + "</HEAD> "
                                  + " <BODY> "
                                  + " <p>test  HTMLEditor</p>"
                                  +  "</BODY> "
                                  +"</HTML>");
              htmlview = new HTMLEditor();
              vbox.getChildren().addAll(btn,htmlview);
              root.getChildren().add(vbox);
              stage.setVisible(true);     
         public static void main(String[] args) {
              Application.launch(args);
    }Edited by: noregister on Aug 4, 2011 6:57 AM

Maybe you are looking for

  • Sorting Photos by Name

    I'm a new Mac user. I've migrated all my photos from PC to iPhoto, but now I'm having a terrible time getting the photos to sort properly by title. I have used a naming convention (topic #) where # starts at 1 and goes up sequentially. However, when

  • Creating 1 spool for every 1000 sapscripts

    Hi Friends , I have a program where i am printing W-2 forms (sapscripts) . There are a total of 3000 forms . I need to be able to split them into 3 spools of 1000 each instead of creating 3000 spools . Please advise as to wat parameters need to be se

  • Save data and tcp connection

    Hi, I have a connection between a measurement roboter and LabVIEW. I transmit the data above an TCP connection (for example the coordinate plane of the sensor). I have different ports to transmit the data. Is it possible to save the transmitted data

  • Permissions trouble moving files -Help

    I am trying to copy a large folder to my external hard drive. I have done this many times before. However, today, it is telling me that I do not have the permissions to do so. What does this mean? How can I correct it? When I click "Get Info" on the

  • SB0460 AC3/DTS decoder not working on Windows 7 (Driver 2.18.0015)

    Hello everybody! I hope somebody will be able to help me with my strange problem: I just did the move from Windows XP (x64) to Windows 7 (x64) and discovered that the X-FI's AC3/DTS decoder is not working. All I get is either noise/static/crackling (