Is it possible (JEditorPane)...?

Is it possible to load a html page in a JEditorPane and then have this page as a background while typing some text inside the same JEditorPane?

I wrote an html editor last month with a 'preview window'. This window was a cobbled together 'basic browser window' with enhanced features built up using a simple JTextPane which in turn encapsulated my own Browser.class. I wasn't very satisfied with some of the features of ready-built widgets from the API so I created my own. This self-built JTextPane widget had local 'file;//' protocol support and CSS, style-sheets, frames, embedded applets, XML-parsing etc. In fact almost everything that any standard browser would do other than javascript.
The effect of this was that the user - ie: the html author, could work with raw html code in the main editor window or directly edit their html in the preview window and save /update their work in either. In short yes its a relatively simple thing to implement - I'm not sure you want to do anything quite so complex as, what became in effect a basic browser. On a simple level, I cannot see any reason why you cannot do this with any rendered html page, even public http:// pages. On a more complex level, you can do whatever you want with java - that's what makes it so sexy.

Similar Messages

  • Different colour text in textarea

    Hi,
    I was hoping someone could tell me whether it's possible to change the colour of text that is appended to a textarea.
    I'm finishing off a chat server/applet project and i thought it would look better if I could colour code the messages that are displayed on the screen. e.g when a user enters a room the text signifying that is displayed in red, when a user leaves the room the text is coloured red etc.
    I would greatly appreciate any help on this
    Chers
    Mikey

    Sadly to say it is not possible JEditorPane or JTextPane is the only way

  • Exceptions with JEditorPane setPage() method (Catching not possible)

    hi all
    if anyone can help me...please help
    I got serious exceptions with the JEditorPane()'s setPage() method
    I have written the try & catch still i could not catch the exception..(those exceptions are not displaying any of my program lines)..setPage() mehod was executed properly and the page was displyed on the editorpane..and then exceptions r coming..
    --------my code--------
    java.net.URL fileurl =LongTask.class.getResource(modifiedfilename);
    editorpane.setPage(fileurl);
    ---------------------exceptions
    java.lang.NullPointerException
    at java.util.Hashtable.put(Hashtable.java:393)
    at javax.swing.text.SimpleAttributeSet.addAttribute(SimpleAttributeSet.java:176)
    at javax.swing.text.html.CSS.translateHTMLToCSS(CSS.java:687)
    at javax.swing.text.html.StyleSheet.translateHTMLToCSS(StyleSheet.java:491)
    at javax.swing.text.html.StyleSheet$ViewAttributeSet.<init>(StyleSheet.java:2476)
    at javax.swing.text.html.StyleSheet.getViewAttributes(StyleSheet.java:312)
    at javax.swing.text.html.BlockView.getAttributes(BlockView.java:275)
    at javax.swing.text.html.StyleSheet$ViewAttributeSet.getResolveParent(StyleSheet.java:2609)
    at javax.swing.text.html.StyleSheet$ViewAttributeSet.doGetAttribute(StyleSheet.java:2589)
    at javax.swing.text.html.StyleSheet$ViewAttributeSet.getAttribute(StyleSheet.java:2569)
    at javax.swing.text.ParagraphView.setPropertiesFromAttributes(ParagraphView.java:105)
    at javax.swing.text.html.ParagraphView.setPropertiesFromAttributes(ParagraphView.java:87)
    at javax.swing.text.html.ParagraphView.setParent(ParagraphView.java:60)
    at javax.swing.text.CompositeView.replace(CompositeView.java:200)
    at javax.swing.text.BoxView.replace(BoxView.java:164)
    at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
    at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
    at javax.swing.text.html.BlockView.setParent(BlockView.java:55)
    at javax.swing.text.CompositeView.replace(CompositeView.java:200)
    at javax.swing.text.BoxView.replace(BoxView.java:164)
    at javax.swing.text.html.TableView$RowView.replace(TableView.java:1414)
    at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
    at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
    at javax.swing.text.CompositeView.replace(CompositeView.java:200)
    at javax.swing.text.BoxView.replace(BoxView.java:164)
    at javax.swing.text.html.TableView.replace(TableView.java:864)
    at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
    at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
    at javax.swing.text.html.TableView.setParent(TableView.java:768)
    at javax.swing.text.CompositeView.replace(CompositeView.java:200)
    at javax.swing.text.BoxView.replace(BoxView.java:164)
    at javax.swing.text.View.updateChildren(View.java:1126)
    at javax.swing.text.View.insertUpdate(View.java:710)
    at javax.swing.text.View.forwardUpdateToView(View.java:1217)
    at javax.swing.text.View.forwardUpdate(View.java:1192)
    at javax.swing.text.BoxView.forwardUpdate(BoxView.java:222)
    at javax.swing.text.View.insertUpdate(View.java:716)
    at javax.swing.plaf.basic.BasicTextUI$RootView.insertUpdate(BasicTextUI.java:1487)
    at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.insertUpdate(BasicTextUI.java:1726)
    at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:184)
    at javax.swing.text.DefaultStyledDocument.insert(DefaultStyledDocument.java:201)
    at javax.swing.text.html.HTMLDocument.insert(HTMLDocument.java:232)
    at javax.swing.text.html.HTMLDocument$HTMLReader.flushBuffer(HTMLDocument.java:3254)
    at javax.swing.text.html.HTMLDocument$HTMLReader.addContent(HTMLDocument.java:3196)
    at javax.swing.text.html.HTMLDocument$HTMLReader.blockClose(HTMLDocument.java:3128)
    at javax.swing.text.html.HTMLDocument$HTMLReader$BlockAction.end(HTMLDocument.java:2334)
    at javax.swing.text.html.HTMLDocument$HTMLReader.handleEndTag(HTMLDocument.java:2233)
    at javax.swing.text.html.parser.DocumentParser.handleEndTag(DocumentParser.java:217)
    at javax.swing.text.html.parser.Parser.parse(Parser.java:2072)
    at javax.swing.text.html.parser.DocumentParser.parse(DocumentParser.java:106)
    at javax.swing.text.html.parser.ParserDelegator.parse(ParserDelegator.java:78)
    at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:230)
    at javax.swing.JEditorPane.read(JEditorPane.java:504)
    at javax.swing.JEditorPane$PageLoader.run(JEditorPane.java:551)
    please share ideas to solve this problem

    But how can I cause GUI thread to run in my thread
    group? As I suppose GUI thread is started by JVM and
    is something separate from my code - I can get a
    reference to GUI thread but don't know how to
    manipulate or replace it...One alternative is to completely separate the GUI code from your code.
    Your code, which is wrapped in appropriate try/catch blocks, runs on its own thread and does its own processing. When it's done with that processing, it queues the results on the event thread for display. If an exception occurs during your processing, then you queue something that notifies the GUI.
    The simplest way to implement this is to spawn a new thread for each operation. The Runnable that you give to that thread looks like the following:
    public MyOperationClass implements Runnable
        public void run()
            try
                // do your exception-generating code here
                SwingUtilities.invokeLater( new MyGUIUpdateClass(param1, param2));
            catch (Exception e)
                SwingUtilities.invokeLater(new MyExceptionReporter(e));
    }This is only a bare-bones solution (and hasn't been compiled). Since it separates the GUI from actual processing, you'll probably want to display a wait cursor while the processing thread is doing its thing. You'll probably end up implementing a class that implements this pattern. You may also want to create a producer-consumer thread, so that the user won't invoke, say, a dozen different operations at once.
    However, this sort of code is absolutely essential to Swing programming. Most apps do extensive non-GUI processing, such as database queries. If you run such queries in the GUI thread, your GUI will freeze.
    Sun has named this pattern "SwingWorker", although I don't think they've fleshed it out very fully: http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html

  • How to insert hyperlinks in RTF document shown in JEditorPane?

    This is a compound question so bear with me on this one :)
    What I need is to insert an hyperlink in a JEditorPane; Store it as RTF code; Retrieve it; Show it and click on it to go the the destination.
    1) So, first question, is there some method to automatically add the hyperlink and will it be saved in RTF with RTFEditorKit? (I'm actually using AdvancedRTFEditorKit but an answer to either will be enough)
    2) I tried a method that adds what appears as a link but the document that is stored doesn't have the necessary RTF codes, only the formatting that makes it look like a link. I also checked the actual RTF codes I'd need to add and they seem easy to do. So, is there a way to add the actual underlying RTF codes to the document while it's in the JEditorPane?
    I know the question(s) isn't too specific, if you can shed some light over the whole thing and point me in the right direction, it'd be great!

    Just a follow up to my own question. I found a way to answer my question 2) and I'm now storing the rtf code for hyperlinks. Now, when I show the document in JEditorPane with RTFEditorKit, I get the name of the hyperlink with no formatting indicating that it's a hyperlink.
    Example. The link "http://www.google.com" with the name "Google", only shows "Google" in plain text.
    Is it because the components I'm using don't support hyperlinks from RTF files even though they're supported from HTML files?
    Is there any way you can see this working? Is it possible to include something inside the JEditorPane that the user can click, instead of the hyperlink?

  • How can I create JEditorPane which scrolls to the bottom on every resize?

    JRE 1.3.0
    Included a simple frame with the only control - JEditorPane (contained within JScrollPane). Every time scroll pane size changes, attempt to scroll down to the end of JEditorPane is made.
    The problem is: although everything works 9 times of 10, sometimes editor is scrolled almost to the end, sometimes - to the very top. On the next resize editor is scrolled correctly.
    I think, there are some delayed layout recalculations inside SWING which prevent JEditorPane and/or JScrollPane from knowing actual size.
    Is it possible to force JEditorPane+JScrollPane pair to update dimensions? ( explicit call to doLayout() does not fix anything )
    Thanks
    public class TestFrame extends JFrame
    BorderLayout borderLayout1 = new BorderLayout();
    JScrollPane jScrollPane1 = new JScrollPane();
    JEditorPane jEditorPane1 = new JEditorPane();
    public TestFrame()
    try
    jbInit();
    catch(Exception e)
    e.printStackTrace();
    private void jbInit() throws Exception
    this.getContentPane().setLayout(borderLayout1);
    jEditorPane1.setContentType("text/html");
    jEditorPane1.setText("test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test ");
    jScrollPane1.addComponentListener(new java.awt.event.ComponentAdapter()
    public void componentResized(ComponentEvent e)
    jScrollPane1_componentResized(e);
    this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
    jScrollPane1.getViewport().add(jEditorPane1, null);
    void jScrollPane1_componentResized(ComponentEvent e)
    Dimension size = jEditorPane1.getPreferredSize();
    jEditorPane1.scrollRectToVisible( new Rectangle(0, size.height, 0, 0) );
    System.out.println("preferred height=" + size.height);
    }

    Seen this thread?
    Return to previously viewed page

  • Print html content of an JEditorPane

    Hello!
    I have an JEditorPane with some HTML Content displayed (as it is displayed in a browser).
    Now i want to sent this content to a printer.
    After some search i found the DocumentRenderer class from this link:
    http://www.fawcette.com/javapro/2002_12/online/print_kgauthier_12_10_02/
    It may be trivial, but i don't know how to create a HTMLDocument Object from my JEditorPane (and its contents).
    Maybe somebody can help me out with this.
    my code so far:
    DocumentRenderer renderer = new DocumentRenderer();
    HTMLDocument doc = new HTMLDocument();
    //At this point i don't  know how to get my JEditorPane/it's contents "into" the HTMLDocument Object
    renderer.setDocument(doc);
    renderer.print(doc);                               Many thanks in advance for help!

    find it out by myself.
    HTMLDocument doc = (HTMLDocument)myJEditorPane.getDocument();But now i ran in another problem:
    Checkboxes are not displayed when i print this content.
    Is it possible to solve this problem?

  • How to retrieve data from the HTML form in the JEditorPane?

    I could quite easily use JEditorPane to render and display a simple HTML file.
    My HTML looks like this:
    <html>
    <head>
    <title> simple form</title>
    </head>
    <body bgcolor="cccccc">
    <center><h1>SURVEY THING</h1>
    </center>
    <form id="survey">
    <p>1.Type something in.</p>
    <textarea cols=25 rows=8>
    </textarea>
    <BR>
    <p>2.Pick ONLY one.</p>
    <input type="radio" name="thing" value="0" Checked> NO choice <BR>
    <input type="radio" name="thing" value="1"> First choice <BR>
    <input type="radio" name="thing" value="2"> Second choice
    <BR>
    <p>3.Pick all you like.</p>
    <input type="checkbox" name="stuff" value="A"> A <BR>
    <input type="checkbox" name="stuff" value="B"> B <BR>
    <input type="checkbox" name="stuff" value="C"> C <BR>
    <input type="submit" value="give data">
    <input type="reset" value="do clensing">
    </form>
    </body>
    </html>
    It gets diplayed fine and I can type in text, select radio buttons (they behave mutualy-exclusive,
    as they should) and check checkboxes.
    The problem I have is with retrieving the values which were entered into the form.
    If I, after editing, try to write the html to the file using HTMLWriter,
    it records the changes I made into the textarea, however all the radio and checkbox selections are lost.
    Maybe the problem is that when I enter the values I do not use any methods like
    insertBeforeStart and so on, but I believe I shouldn't need to use them to populate a form.
    Especially I never change the structure of the HTML.
    Also, when I try to traverse the Element tree and see the input elements attributes,
    I can never see a change in the entered values. However it is probably b/c I am traversing through
    the model and the changes are in the view (just a guess.)
    Anyway, if anybody could direct me onto the right path: how to retrieve the values typed in the form,
    or if it is possible at all in the JEditorPane, I would greatly appreciate.
    thanks
    maciej
    PS. I have seen the answer to a similar question posted some time last year. However, I am trying
    to find a soultion which allows forms/surveys to be built by people who have no java and only basic
    html knwledge. And Axualize way is probably a little bit too "high-tech."

    Maybe helpful for u.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Container;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    public class TestHtmlInput extends JFrame {
         JEditorPane pane=new JEditorPane();
         public TestHtmlInput() {
              super();
              pane.setEditorKit(new HTMLEditorKit());
              pane.setText("<HTML><BODY><FORM>" +
              "<p>1.Input your name.</p>" +
              "<INPUT TYPE='text' name='firstName'>" +
              "<p>2.Input your information.</p>" +
              "<TEXTAREA rows='20' name='StationDescriptions' cols='100'>" +
              "<p>3.Pick ONLY one.</p>" +
              "<input type='radio' name='thing' value='0' Checked> NO choice <BR>" +
              "<input type='radio' name='thing' value='1'> First choice <BR>" +
              "<input type='radio' name='thing' value='2'> Second Choice <BR>" +
              "<p>4.Pick all you like.</p>" +
              "<input type='checkbox' name='stuff' value='A'> A <BR>" +
              "<input type='checkbox' name='stuff' value='B'> B <BR>" +
              "<input type='checkbox' name='stuff' value='C'> C <BR>" +
              "<p>5.Choose your nationality.</p>" +
              "<select name='natio'>" +
              "<option>12</option>" +
              "<option selected>13</option>" +
              "</select>" +
              "</FORM></BODY></HTML>");
              this.getContentPane().add(new JScrollPane(pane));
              JButton b=new JButton("print firstName text");
              b.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        System.out.println("Number of Components in JTextPane: " + pane.getComponentCount());
                        for (int i = 0; i <  pane.getComponentCount(); i++) {
                             //NOTE FOR BELOW: know its a Container since all Components inside a JTextPane are instances of the inner class
                             //ComponentView$Invalidator which is a subclass of the Container Class (ComponentView$Invalidator extends Container)
                             Container c = (Container)pane.getComponent(i);
                             //the component of this containers will be the Swing equivalents of the HTML Form fields (JButton, JTextField, etc.)
                             //Get the # of components inside the ComponentView$Invalidator (the above container)
                             Component swingComponentOfHTMLInputType = c.getComponent(0);
                             //each ComponentView$Invalidator will only have one component at array base 0
                             //DISPLAY OF WHAT JAVA CLASS TYPE THE COMPONENT IS
                             System.out.println(i + ": " + swingComponentOfHTMLInputType.getClass().getName());
                             //this will show of what type the Component is (JTextField, JRadioButton, etc.)
                             if (swingComponentOfHTMLInputType instanceof JTextField) {
                                  JTextField tf = (JTextField)swingComponentOfHTMLInputType;
                                  //downcast and we have the reference to the component now!! :)
                                  System.out.println("  Text: " + tf.getText());
                                  tf.setText("JTextField found!");
                             } else if (swingComponentOfHTMLInputType instanceof JButton) {
                             } else if (swingComponentOfHTMLInputType instanceof JComboBox) {
                                     JComboBox combo = (JComboBox)swingComponentOfHTMLInputType;
                                     System.out.println("  Selected index: " + combo.getSelectedIndex());
                                } else if (swingComponentOfHTMLInputType instanceof JRadioButton) {
                                     JRadioButton radio = (JRadioButton)swingComponentOfHTMLInputType;
                                     System.out.println("  Selected: " + new Boolean(radio.isSelected()).toString());
                             } else if (swingComponentOfHTMLInputType instanceof JCheckBox) {
                                     JCheckBox check = (JCheckBox)swingComponentOfHTMLInputType;
                                     check.setSelected(true);
                                     System.out.println("  Selected: " + new Boolean(check.isSelected()).toString());
                             } else if (swingComponentOfHTMLInputType instanceof JScrollPane) {
                                  JScrollPane pane = (JScrollPane)swingComponentOfHTMLInputType;
                                  for (int j=0; j<pane.getComponentCount(); j++) {
                                       //JTextArea area = (JTextArea)swingComponentOfHTMLInputType.getComponent(0);
                                       Container c2 = (Container)pane.getComponent(j);
                                       for (int k=0; k<c2.getComponentCount(); k++) {
                                            Component c3 = (Component)c2.getComponent(k);
                                            if (c3 instanceof JTextArea) {
                                                 JTextArea area = (JTextArea)c3;
                                                 System.out.println("  " + area.getClass().getName());
                                                 System.out.println("     Text: " + area.getText());
                                                 area.setText("JTextArea found!");
                             } else {
              this.getContentPane().add(b,BorderLayout.SOUTH);
         public static void main(String args[]) {
              TestHtmlInput app = new TestHtmlInput();
              app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              app.setSize( 400, 900 );
              app.setVisible( true );
    }

  • A shared Text editor - question about JEditorPane

    Hi there,
    I'm trying to make a shared Text Editor. So far I have the ability to pass messages across from one client to another. I have all the GUI elements in the "main" Class, and the Connection elements in separate Classes; in particular the receivedPacket method which listens for specific packets. Now I'm able to print in my Terminal window the received packets (via a simple System.out.println call). Is it possible to grab the packet information from the "main" Class and then append that information to the JEditorPane (which has been constructed in the main Class)? Or would it be better to create the JEditorPane in the Class with the receivedPacket and then add the information straight away to the editor window?
    Thanks
    :)

    Thanks for the guidance, I think you're right. Nice to hear you've done something similar.
    What I have up and running is:
    1) GUI elements created in the main class (Class Exchange)
    2) A Connection class that handles the connection to the server and adds packet listeners to the incoming packets (Class Connection)
    3) A class that filters and stores the packets (Class Comms)
    Now I'm using a protocol called Jabber (instant messaging protocol) so I'm using the JabberBeans library for all Jabber stuff (i.e. Connection and packet listeners etc..). Now the receivedPackets method within the Comms Class then extracts the <body> of what I want to another method within the Comms Class which then returns that String value. This works as it prints to the Terminal window when run and packets are received.
    What I'm having difficulty in understanding (although I think its straightforward) is why I can't take that returned value and have it update in my JEditorPane window (which is in the main Class (Exchange)), it doesnt like it for some reason and complains about something from the JabberBeans library.
    I'm unsure about how to update the JEditorPane; would it be to write a method in the main class that calls in the returned <body> String value (which is what I thought would be right)? Or is there something else I've missed. In the JabberBeans API the returned value is of type String, I'm guessing that maybe I need to move that into a StringBuffer for the sake of the JEditorPane.. Or is that just guessing?
    Thanks for the help, hope you get a moment..
    AB
    :)

  • JEditorPane and JTree

    Hi,
    I have a tree that lists all objects and I want to do some kind of search feature. Results would be displayed in JEditorPane but I don't know anything about that. In JTree there is TreeSelectionListener (method valueChanged) and that has the functionality I need to have on JEditorPane but I don't know if this is possible?
    Any advices please?

    Hi,
    I have a tree that lists all objects and I want to do some kind of search feature. Results would be displayed in JEditorPane but I don't know anything about that. In JTree there is TreeSelectionListener (method valueChanged) and that has the functionality I need to have on JEditorPane but I don't know if this is possible?
    Any advices please?

  • JEditorPane html display problem

    Hello,
    I'm running a JEditorPane inside an Applet for a project im working on. The source included below is an over-simplified version that produces the same results. The problem i'm having is that the html displays in an odd fasion in the JEditorPane.
    Since I cant include a screenshot let me attempt to describe it. Regardless of the FONT face in the html the paragraph displays as you would expect in the JEditorPane until the last line. The last has extra horizontal space separating it from the rest of the paragraph. This seems completely arbitrary. There is nothing in the html code near the line break.
    I've linked this problem to the font face attribute tags. Regardless of the font I choose it displays improperly. Any idea on how to remove this spacing problem in my JEditorPane?
    I'm using NetBeans 3.5.1 and SDK 1.4.2. I've tested this problem in the AppletViewer as well as online in a web browser.
    * CourierTest.java
    * Created on July 24, 2004, 8:28 PM
    import java.awt.Font;
    import java.io.*;
    * @author LD Miller
    public class CourierTest extends javax.swing.JApplet {
    String html;
    /** Initializes the applet CourierTest */
    public void init() {
    initComponents();
    html = "<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><FONT size=3><FONT face=\"Times New Roman\">What is event-driven programming?It is a <I>computer programming</I> paradigm that is different from traditional, sequential programming. In traditional, sequential programming, one could follow the program and plot out exactly the sequence of execution of the program. However, in event-driven programming, it is not possible to plot out exactly the sequence of execution of the program since flow of the execution is determined by the events. Event-driven programming allows a program to interact with users and re-act to user-generated events in a more efficient and effective manner. </FONT></FONT></P>";
    jTextPane1.setContentType("text/html");
    jTextPane1.setText(html);
    /** This method is called from within the init() method to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextPane1 = new javax.swing.JTextPane();
    jScrollPane1.setViewportView(jTextPane1);
    getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration

    1) I have complex html page (having lot of html controls).
    .when i resize the container, controls gets overlapped.
    shall we avoid this? to my experience JEditorPane deviates from the display of typical browsers when HTML is displayed that contains complex table layouts (tables nested in other tables or non-explicit or non-existent size expressions in tables for instance). I recommend to try and simplify layout complexity as a workaround. Start with a most simple page and increase complexitiy until display gets unsatisfactory.
    2) I used JEditorPane. My html contents are stored in
    text. i called setText()...whether i need to use
    HTMLDocument, HTMLEditorKit etc...to render
    html in better way...I did not understand your second point, what is the question?
    Ulrich

  • JEditorPane not Displaying HTML Correctly

    I have a section of code that needs to lookup the HTML for a given URL, and then store the HTML for future use. The problem is the HTML is displaying in the JEditorPane as text rather than rendering it as HTML.
    I've stripped the code down as much as possible to work this out. The code to set up the JEditorPane;
         jepLocal = new JEditorPane();
            jepLocal.setEditable(false);
            jepLocal.addHyperlinkListener(new LinkFollower(jepLocal));
            // these 2 lines set the jep for syncronous operation ...
            JEditorPane.registerEditorKitForContentType( "text/html", "HTMLEditorKit2" );
            jepLocal.setEditorKitForContentType( "text/html", new HTMLEditorKit2() );
            jepLocal.setPage(urlArray[0]);
    htmlString = jepLocal.getText();
    I'm using a simple class to set the jep into syncronous mode for retrieval. Here is that class;
    class HTMLEditorKit2 extends HTMLEditorKit{
      public Document createDefaultDocument(){
        HTMLDocument myDocument = (HTMLDocument)(super.createDefaultDocument());
        myDocument.setAsynchronousLoadPriority(-1); // load synchronously
        return myDocument;
      }The code runs in it's own thread, in case that matters.
    Can anyone see what is wrong with this setup? When I feed the htmlString into another jep, I get text display of the html rather than rendered.
    Bernie

    When I feed the htmlString into another jep, I gettext display of the html rather than rendered.
    How are you "feed[ing] the htmlString into another
    jep?" Does the other JEditorPane know it's text/html
    rather than text/plain?
                    myThis.getEditorPane().setText(htmlString);The other jep is in the main gui thread. It loades web pages fine when it's handed a URL and the extracted HTML can be saved and redisplayed using the setText method like above. This jep has all the same setup code, including the EditorKit inclusion.
    Bernie

  • Windows 98 not  showing JEditorPane control

    hi,
    i am new to java. I installed j2se sdk 1.4.2_07 version in my windows 98 os.
    and set the class path to c:\j2se sdk 1.4.2_07\bin in the AUTOEXEC.bat file itself
    My friend gave one program(swing application) to run which contain JEditorPane control. It is not displayed in the windows98 but it was developed in win2000prof OS.
    Why it is not displaying this control?
    Is any other thing needed to run the java program
    and I saw that some thing JRE in this web site. wht is that? Do i have to install that too in my system?
    Please give me a solution
    Thank you in advance for reply
    Regards,
    Mahendranath

    Freddy,
    You didn't have the CDDB, ASIO stuff because you probably hadn't installed Creative software like PlayCenter, the SurroundMixer, etc.
    Thanks for the complements, but I've noticed intelligent life on this board. Some of those are forced to offer basic advice that doesn't include 3rd party programs that can help since they are Creative employees.
    It sounds like you got Windows to install whatever vxd drivers you have through the inf file using Device Manager. Regardless, it also sounds like you have analog speakers but the driver might be set to digital output only. This is a setting normally accessible from Creative's SurroundMixer, which you don't have I guess. The inf might have been written to make that setting by default unless changed during the install by selecting a specific speaker set, which was not available to you since you're not using a setup file to install the driver.
    It's possible you don't have the correct drivers for your model card. You managed to install the vxd version of what you've got, but the driver itself might not have the correct files to run your hardware properly.
    You might want to bite the bullit and call Creative's customer service and order the proper installation cd for your card. An option to consider if you get that and find it still only starts its support with 98 2nd edition is to find (ebay, searching) someone who'll sell you the old, discontinued Microsoft Windows 98 Second Edition Update cd. It originally sold for $20 and would update an existing 98 st edition system to 98 2nd edition. The only difference between it and the full $00 98 Upgrade cd was you couldn't do a fresh install with it. You needed 98 st edition actually installed first.
    Before that, you can try driverguide.com and see if someone posted something there that might work.
    Good Luck.

  • Inserting any JComponent in a JEditorPane

    Hi, I'm having some trouble using JEditorPane and JTextPane. I would like to include some JComponent of my own into them.
    With JTextPane, no problem, let's create a style with
    StyleConstants.setComponent(myStyle, myComponent);
    then insert a space char in the Document using this style. Good.
    Problem comes when I want to insert my components into an HTML document, using JEditorPane. This method raises no runtime problem but does nothing visible. Why ? Even more surprising, if I force the JEditorPane to a simple DefaultStyledDocument
    JEditorPane editorPane = new JTextPane();
    editorPane.setDocument(new DefaultStyledDocument());
    it doesn't work better. In such a case, ain't we in exactly the same configuration than with JTextPane ? BTW, why is JTextPane derived from JEditorPane if we cannot retreive parent's behaviour (HTML or RTF rendering) in the child class ?
    Yes, I'm confused...
    If your mind is clearer than mine on those topic, could you give me a piece of advice, or a link to a solution or an exemple on all of this ? Thanks,
    Matthieu

    No idea anybody on how I could insert JComponents of my own in a JEditorPane ?
    Why the simple Document.insertString () don't work in a JEditorPane if the style is not HTML ?
    Is it possible to tweak JTextPane to make it render HTML (using a Kit) then insert my own styles in it ?
    Thx.
    Matthieu

  • Caret position in JEditorPane HTML

    Hi everyone,
    I need the position of caret in HTML source on JEditorPane. I
    The value of getCaretPosition() seems not what I wanted. CaretEvent.getDot() gives the same value of getCaretPosition. These methods only gets position on the view.
    Please help! Thanks a lot!

    It's not possible. HTMLParser creates Document's structure (Elements tree) from html text but it has no relation to content.
    Position in source html isn't correct because it may contain unnecesary space between tags or tab chars or \n chars which are ignored.

  • URGENT: JEditorPane (a Java Browser) displaying HTML form

    Hi,
    I am using JEditorPane to display the wb pages but geeting problem as
    I don't get any kind of event when I click on the HTML form SUBMIT button though it does work but didn't allow me to get the URL of the new page that I got after hitting this SUBMIT button..
    I searched the whole net and it seems to me that lot of people got this problem...
    As I need this for my project please HELP me as soon as possible.

    This may be too late for you (hopefully not), but I had the same problem a little while ago and just figured out how to fix it. Basically, you need to examine the Element structure of the html yourself and manually handle the form, as far as I can tell. There are several ways to display a URL in a JEditorPane, but the most straight-forward (JEditorPane.setPage(URL url)) doesn't actually store the Element structure anywhere accessible. Here's the code to load the page:
    JEditorPane contents;
    HTMLEditorKit kit = new HTMLEditorKit();
    HTMLDocument htmlDoc = new HTMLDocument();
    contents.setEditorKit(kit);
    contents.setDocument(htmlDoc);
    URL url = new URL("http://blahblahblah.com");
    contents.read(url.openStream(), htmlDoc);Now that you have the page loaded correctly, you can access to the Elements within. You can use htmlDoc.getDefaultRootElement() to get the root and then iterate recursively through all the child Elements, checking out the Attributes of each. This will look for the submit button and add a listener to it for you:
    private void parseElements(Element elem) {
        AttributeSet atts = elem.getAttributes();
        //If this is the submit button, add a listener:
             Object model = atts.getAttribute(StyleConstants.ModelAttribute);
             Object type = atts.getAttribute(HTML.Attribute.TYPE);
             if ((type != null) && (type.equals("submit"))) {
                 DefaultButtonModel btn = (DefaultButtonModel) model;
                 btn.addActionListener(new ActionListener() {
                     public void actionPerformed(ActionEvent event) {
                         System.out.println("Yay!");
        //Recurse
        for (int i = 0; i < elem.getElementCount(); i++)
             parseElements(elem.getElement(i));
    }Of course, printing out "Yay!" is not really very helpful. When you're parsing through the Elements, check for the attribute StyleContsants.ModelAttribute. If that exists, you can cast it to the correct type of Model (see the documentation for HTMLDocument.HTMLReader.FormAction for information about what types of models to expect from what types of HTML elements) and store it until the "submit" button is pressed. Then all you have to do is get all the data from the models, format it and submit it to the action URL in either a "get" or a "post." The action URL is stored, in Java 1.3, in the HTML.Tag.Form attribute of one of the Elements (I don't remember which one). Getting that attribute returns a SimpleAttributeSet, and you get the HTML.Attribute.Action out of that. In Java 1.4 it's easier to find, you just have to look for the HTML.Attribure.Action attribute in one of the Elements.
    Why isn't this all automatically done for you? I don't know. Good luck.
    -Nathan

Maybe you are looking for

  • Lumina 1020 Video Out Help

    I love the phone, but it always seems I am getting jacked by MS, I have the Surface RT, several HTC phones that the carrier wont upgrade from WP7... so I am pretty fustrated with MS... Now my iPhone I can mirror image it to display on anything with a

  • Adobe Premiere and Flash

    Forgive me if this is a stupid question, but I know virtually nothing about Flash, and have a somewhat limited background in Adobe Premiere. I want to create a Flash intro for my Web site, and I was figuring I could do it first as a video/audio clip

  • About save local file

    hi expert: i open file saved via system->save->local file-> spreadfile almost line item can be displayed correctly.. but some records are hidden into the description field of previous entry. perhaps some special character exist in description field f

  • Invoice output - item list with qty but prices summarized @ item type

    Hi SAP gurus Below is my client requirement.This is for invoice of service contract.Consider the example below and p;s guide me how to follow the proceess by possibility? Contract no :123 Material 1 (type A)- Qty -1 - Monthly Support fee - 100$ Mater

  • Weird floating, blurry screen

    I had turned my computer off over the holidays and booted it up when I returned and the screen is kind of blurry. But worse is the screen seems too big for the monitor. As I move the mouse the screen moves with it. The dock at the bottom of my screen