Html files, images and JEditorPane

Hello all,
I've got some HTML file that need be displayed in a JEditorPane. Those HTMLs contain image references and I'm using relative paths to those jpegs, for example:
<img src="image.GIF">
...where image.gif is in the same folder as the HTML file that contains the reference. Now I'm displaying this HTML file inside a JEditorPane and I get only a placeholder instead of the image; only text gets displayed properly.
Here's how I'm constructing the JEditorPane instance:
          pane = new JEditorPane();
          pane.setEditable(false);
          pane.setContentType("text/html");
          HTMLEditorKit kit = new HTMLEditorKit();
          kit.createDefaultDocument();
          pane.setEditorKit(kit);and later...
      try {
          URL u = new URL("file", "localhost", ivHelpPath);
          pane.setPage(u);
        } catch (IOException iox) {
        }I saw on some other thread that I should be setting the document's base URL for the reference I get from getDocument(), but that does not seem to work when I use "http://localhost/" to make my URL object.
So... help! :)
Thanks much.

Not sure what you're trying to do with new URL( "file" "localhost", ...
Try this code and see if it helps you - display a page that already exists though - perhaps that's the diff?
    JTextPane() jtp = new JTextPane(); //JEditorPane();
    jtp.setEditable( false );
    JScrollPane jsp = new JScrollPane( jtp,
                                 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
    ( ( HTMLEditorKit ) ( jtp.getEditorKit() ) ).setLinkCursor( new Cursor( Cursor.HAND_CURSOR ) );
    jtp.addHyperlinkListener( new HyperlinkListener() {
      public void hyperlinkUpdate( HyperlinkEvent hle ) {
        try {
          if ( hle.getEventType() == HyperlinkEvent.EventType.ACTIVATED )
            jtp.setPage( hle.getURL() );
        } catch( Exception e ) {
          // do something;
    });... There's also code here that will activate hyperlinks which you may or may not want. But this will display embedded .gif files.

Similar Messages

  • Writing html file in a jeditorpane

    I have read one of your threads titled as "How to insert a string in a JEditorPane (Urgent)". according to this thread I am using insertString() method to write in an jeditorpane. what I am writing is an html file. when I used insertString() method it doesn't show the html content in my jeditotpane. it displays the source code of my html file. I have setContentType("text/html"); moreover I used setText() and it shows the html file correctly but it over writes the previous content of jeditorpane. please help me to be able to
    write to a jeditorpane without overwriting and displaying html file properly not its source code.
    following is my code:
             fr = new FileReader("myfile.html");
         BufferedReader br = new BufferedReader(fr);
         while ((lineread = br.readLine()) != null)
              find.append(lineread);
                       do{
                             last = find.lastIndexOf("str");
                          Integer index = myJEditorPane.getSelectionEnd();
                   String temp = index.toString();     
                   start=find.indexOf(temp, end);
                   end=find.indexOf("str", start);
                            Document doc = mynewContentPane.getDocument();
                   try{
                        doc.insertString(doc.getLength(),find.substring(start, end),null);
                   catch(BadLocationException exc){
                        exc.printStackTrace();
                   }Edited by: nasi on May 7, 2010 8:59 PM
    Edited by: nasi on May 8, 2010 12:09 AM
    Edited by: nasi on May 8, 2010 1:37 AM

    Welcome to the Sun forums.
    Subject: writing html file in a jeditorpane
    If you mean a JEditorPane then please use the correct case, so we can be confident you refer to the J2SE class, as opposed to a 3rd party jeditorpane that we neither know, nor support.
    nasi wrote:
    I have read one of your threads titled as "How to insert a string in a JEditorPane (Urgent)". ..I guess you mean [How to insert a string in a JEditorPane (Urgent)|http://forums.sun.com/thread.jspa?threadID=282569] from 2002. A lot has changed since 2002, but I suspect the basic way of appending text to a Document has not.
    BTW - Good to see you arrive with some Google-foo. ;-)
    ..according to this thread I am using insertString() method to write in an jeditorpane. what I am writing is an html file. when I used insertString() method it doesn't show the html content in my jeditotpane. it displays the source code of my html file. I have setContentType("text/html"); moreover I used setText() and it shows the html file correctly but it over writes the previous content of jeditorpane. I've not played much with changing existing documents, but try this source (adapted from code nabbed from the thread you mentioned).
    import javax.swing.text.*;
    import javax.swing.*;
    public class InsertStringTest {
        public static void main(String[] args){
            Runnable r = new Runnable() {
                public void run() {
                    //set GUI
                    JFrame f = new JFrame();
                    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    JEditorPane editorPane = new JEditorPane();
                    editorPane.setContentType("text/html");
                    editorPane.setText("<html><body><h1>Test!</h1><p>");
                    f.getContentPane().add(new JScrollPane(editorPane));
                    String testStr = "This is a test string. " +
                        "This is a test string. This is a test string. \n";
                    f.pack();
                    f.setSize(400,300);
                    f.setVisible(true);
                    //test with insertString()
                    long diff;
                    long startTime = System.currentTimeMillis();
                    Document doc = editorPane.getDocument();
                    for(int i=0; i < 500; i++){
                        try{
                            doc.insertString(doc.getLength(),testStr,null);
                        catch(BadLocationException exc){
                            exc.printStackTrace();
                    diff = System.currentTimeMillis() - startTime;
                    System.out.println("Time spent with doc.insertString() : " + diff);
                    editorPane.setCaretPosition(0);
            SwingUtilities.invokeLater(r);
    }

  • Batch Edit Multiple HTML files | Find and Replace

    Hi,
    I would like to use Automator to automate (I know that sounds redundant) the following process.
    1. Take a group of html files
    2. Open each file so it can find and replace the script of any image folders
    Example:
    Change: img src="home_files/photo.jpg" to img src="images/photo.jpg"
    3. Save & Close each file
    I assume this this would have to be done in either AppleScript or Cocoa.
    Any help would be greatly appreciated.
    Thanks in advance.

    you most definitely don't need Cocoa for something like that. if all you need is a straightforward search and replace in a bunch of html files you can easily do this with a shell script. If you need some more involved search and replace you have to explain what it is exactly that you want.
    to automate direct search and replace you can do something along the following lines in automator
    1. get selected finder items (this will select your html files)
    2. run shell script action with input passed as arguments
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #ADD8E6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    for f in "$@"
    do
    fl=`echo "$f"`
    sed 's%home_files/photo.jpg%images/photo.jpg%g' $f > /users/$USER/.tmp.txt
    cat /users/$USER/.tmp.txt > "$fl"
    done
    rm /users/$USER/.tmp.txt</pre>

  • Where do i place my html files,classes and Java files

    Can any one plz help me out here. I'm using Tomcat3.2.1 to
    run my servlets, I have written the servlets and gotten
    tomcat to run as well. What confuses me now is where my
    files should be placed.
    - Do i have to create a special directory to contain my html
    files ?
    - another directory for my servlet classes ?
    - how about my .java files ?
    - and how should i call my servlet from the html code ?
    HEEEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLPPPPPPPPPPPP!!!!!!!!!!!!!!!

    hi,
    you can my post here http://forum.java.sun.com/thread.jsp?forum=33&thread=302433

  • Viewing PDF or CHM (compiled HTML) files in a JEditorPane (Editorkit av.?)

    I want to view PDF or CHM files in a JEditorPane, for example for use in JavaHelp. Does anybody know if there is a free EditorKit available for viewing at least one of these two kinds of files (especially for PDF), or if it is possible to "plug" the Adobe Acrobat reader into a JEditorPane???

    a usuful url, but I'am afraid this is not the answer for the question :)
    as far as I know, either Sun or other third vendor does not provide the toolkit for PDF
    or CHM viewing in JEditorPane.

  • Print html to image and create pdf

    Hi!
    I'm looking for a way to convert html-pages to fairly good looking pdf-files. As far as I have found there are only one product that can do this and they will not stay in budget.
    So I wonder if there is a way to "print" the html to an image that one then could add to a pdf document, perhaps with iText.
    Has anyone done this before? Is it even possible with the tools available for our budget.
    Thank you very much in advance
    Roland Carlsson

    www.fineprint.com
    $50 for pdf creator.
    they also have fineprint that allows you to print multiple pages per page and save it as image or you can then send it to print to another printer driver <ie the pdf creator>
    both bundled together comes to $80USD

  • HTML of image into JEditorPane

    I was wondering is it possible put HTML text into JEditorPane which contains image so that image can be viewed into JEditorPane.
    This is my code:
    JEditorPane jep = new JEditorPane();
              jep.setContentType("text/html");
              jep.setText("<html><img src=\"SomeImage.bmp\"/></html>");
              jep.setEditable(false);Did I write wrong HTML code into setText() method?
    How to put image with HTML code into JEditorPane?

    Works for me -- maybe you are having path problems:
    import java.io.*;
    import javax.swing.*;
    public class Test {
    public static void main(String[] args) throws
    IOException {
    String text = "<html><body><img
    src=\"http://today.java.net/jag/bio/JagHeadshot.jpg\"
    </img></body></html>";
    JEditorPane editorpane = new
    JEditorPane("text/html", text);
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new
    JScrollPane(editorpane));
    f.setSize(800,600);
    f.setVisible(true);
    }Also: why the requirement to use JEditorPane? There
    are simplier ways to display an image!Your String text variable uses as image source URL link. I use local file.
    Well, it's not strict requirement for me to use JEditorPane for displaying image. In fact, you could tell me some simpler ways?

  • How can i copy and past music files, Images and Videos to my Apple Iphone?

    I have a new Iphone 4 mobile phone. Any one can  help me  for how can i stote music,videos and images files in My Iphone?
    When i search on internet i saw icloud and itunes. Is there any net connection requered to use icloud or itunes? Without net connect how can i store my files in my apple phone?

    Prabakhar,
    First, please verify that you mean CDDA and not CDA.  CDA is not an audio format.
    CDDA is pretty much the "raw" format of an audio CD.  It is extremely unusual to have it as a separate file.  If you still have the original CD that it came from, re-rip the CD using this document.  (Edit added.  I meant to add the link to this document:  http://support.apple.com/kb/PH12486  )
    Otherwise, a web search will turn up converters that can process a CDDA file, although I have not used them.
    Message was edited by: ed2345

  • Save as, type files, images, and documents

    Is it possible in flash to embed links to use right click save as for large documents.
    I know that you can open a pdf in another browser but what about a file that you just want people to be able to save and not open.

    If your linked file is zipped, it will be downloaded and not opened.

  • Idle url GIF file Image and XML file required.* for 7970

    Can anyone supply me a working xml and gif file for the Cisco 7970 colour phone?
    Has anyone actually got this working?
    Thanks!

    First, get the terms right.
    Idle screen is idle screen. Does not need to have anything to do with CCMCIP directory.
    You can set the phone "Device" to ANY server which is running a HTTP server and is able to send headers. Apache. IIS. You name it.
    What you have to do is to
    - make a PNG file accessible using HTTP. Say, it will be http://someniceserver/ipphonestuff/neatpic.png
    - create an XML file with the description I already provided and change the URL to http://someniceserver/ipphonestuff/neatpic.png
    Voila.

  • HTML file is not being shown properly in the JEditorPane

    Hi,
    I am using JEditorPane to display an HTML file from the local disk. This HTML file contains the html tables. Now when this file is getting displayed in the JEditorPane, one top row grid is not being displayed in the editor pane. content of the row is there...but the column grid is missing. All other rows and columns are being shown but the first row-column grid which contains the heading for column.
    Also when I m printing the content of this JEditorPane using Java Print API then no grid is being printed on the paper. content is coming properly but no table grids. when i have taken the print out of the original html file from the browser then table grids are being printed out properly.
    Please do help me out in showing the HTML file in the JEditorPane properly and printing the same.
    Many Thanks,
    gshankar

    Hi,
    JEditorPane renders HTML with many limitations.
    You can use JDIC for the same. refer: jdic.dev.java.net
    But JDIC does not work on windows 98.
    Anand

  • Xml to JTree, and JTree node to html file.

    I have been trying to figure out a way to do this and I think I have a solution, but I am not sure how to structure the application and methods.
    working with BorderLayout Panel p, JSplitPane split, JTree tree, and JEditorPane rpane
    1st. My JSplitpane is divided with the tree, and rpane. The tree is on the left, and the rpane is on the right. both of these are then added to the Panel p
    2. I will create a method that will read through a modules.xml file, and create a JTree - tree. When you click on the node element it's information is displayed in the right pane - rpane.
    The Problem. I think it would take to long to create the html file on the fly each when I click on each individual node.
    So my idea is to create the html files from many xml files when I run the program. I can then just load the html file when I click on each individual node.
    This means alot of heavy processing in the front end, and everything will be static, but it will be faster when the user is in the program.
    Problem. How do I associate each node element with the correct html file?
    The Tree elements are always the same, but I can have 1 or many modules.
    Here is an example:
    <device>  // - root
       <module1>
          <Status>
             <Network></Network>
             <Device></Device>
             <Chassis></Chassis>
             <Resources></Resources>
          </Status>
          <ProjMngt></ProjMngt>
          <ProjEdit></ProjEdit>
          <Admin>
             <admNetwork></admNetwork>
             <admUsers></admUsers>
          </Admin>
          <Logging></Logging>
       </Module1>
       ...  Now I can have 1 or many Modules depending on what the xml file  has in it.
       <Module*n>
    </device>Other problems. Some of the information I want to store as a sortable Table, but I cannot seem to get any of the sort methods to work. They work if I just open a browser, and run the html file, but if I stick the html file into the JEditorPane it does not work? - any suggestions?
    Also, can I pass a JTabbebPane to the JEditorPane, or can I create a tabbed pane in html that will do the same thing.
    I am working with a very small device. It does not have a web application container like Tomcat on it. Just Apache, and Java. That is why I am using Swing.

    Using 'productAttribute/text()' gets you all three productAttribute nodes and then grabs all the text under that node. It simply concatenates together all the text under the desired node, hence the results you are seeing. If you want to get the text for each child node separately, then you need to do something like (assumes 10.2.x.x or greater)
    WITH your_table AS (SELECT
    '<root><productAttribute>
    <name>Baiying_attr_03</name>
    <required>false</required>
    </productAttribute>
    <productAttribute>
    <name>Baiying_attr_04</name>
    <required>false</required>
    </productAttribute>
    <productAttribute>
    <name>Baiying_attr_05</name>
    <required>false</required>
    </productAttribute></root>' xmldata
    FROM DUAL)
    -- Above simulates your DB table as I don't have it
    -- You only care about the following
    SELECT xt.*
      FROM your_table yt,
           XMLTable('/root/productAttribute'
                    PASSING XMLTYPE(yt.xmldata)
                    COLUMNS
                    prd_nm   VARCHAR2(30)  PATH 'name',
                    prod_rqd VARCHAR2(5)   PATH 'required') xt;Note: I added a <root> node as you had just provided a XML fragment. You will need to adjust accordingly.
    The above produces
    PRD_NM                         PROD_RQD
    Baiying_attr_03                false
    Baiying_attr_04                false
    Baiying_attr_05                false

  • How to put an HTML file into JEditorPane

    Hi
    I am doing an aplication on swing.But I don't know how to add a html file to the JeditorPane keeping the html file on the source code. i.e my html file is in my source code.Then how to add this source code to Jeditor pane.
    Thanks
    Srikant

    hi srikkant,
    ur html code is inside the source code..? are you working on applets..? if ur html file can be read as a file and the file stream can converted to a string and put into a Jeditor pane using the setText() method. for editing HTML text a editor called javax.swing.text.html.HTMLEditorKit can be used.
    Refer to JAVA API for further clarifiactions and examples.

  • How to add a html file into JEditorPane

    Hi
    I am doing an aplication on swing.But I don't know how to add a html file to the JeditorPane keeping the html file on the source code. i.e my html file is in my source code.Then how to add this html file to Jeditor pane.
    Thanks
    Srikant

    QuickTime requires player and plugins that most people don't have.  You'll reach a much wider audience if you use HTML5 <video> with mp4, webm and ogg files.
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>HTML5 with Video</title>
    <!--help for older IE browsers-->
    <!--[if lt IE 9]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    </head>
    <style>
    video {
        max-width:100%;
        display:block;
        margin:0 auto;
    </style>
    <body>
    <h2>Use 3 File Types to support all browsers &amp; mobile devices:  MP4, WEBM and OGV.</h2>
    <h3>Online Video Converter
    http://video.online-convert.com/</h3>
    <!--begin video-->
    <video controls poster="Your_poster_image.jpg">
    <!--these are 6 sec sample videos for testing purposes. Replace sample-videos with your own files-->
    <source src="http://techslides.com/demos/sample-videos/small.webm" type="video/webm">
    <source src="http://techslides.com/demos/sample-videos/small.ogv" type="video/ogg">
    <source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4">
    If you're seeing this, you're using an
    outdated browser that doesn't support
    the video tag. </video>
    <!--end video-->
    </body>
    </html>
    Nancy O.

  • I moved a html file and now the page doesn't have a background

    I was trying to remove the .html tags from my web pages and followed the advice on this past post. I created a new folder in Dreamweaver's File tab, then moved the .html file over and renamed it to index.html. Unfortunatley the swf and background images are broken and can't reference them. I'm wondering what step I missed, or how can I relink them?
    Original how to remove .html link discussion I referenced.
    http://forums.adobe.com/message/722731#722731
    I wanted to try and use .htaccess with my current GoDaddy account, but I couldn't get that working correctly.
    http://simplemediacode.info/remove-index-html-andor-index-php-from-the-url/
    My website blank page.
    http://www.victorylcms.org/testimonials/
    Thanks for any help!

    You have bad paths to all your external CSS and Scripts. Typically when you move a file into a folder in the Files Panel, DW will ask you if you want to update links.  You should have hit YES.
    To fix the problem, change all of this in your code:
    <link href="style.css" rel="stylesheet" type="text/css" />
    <link href="layout.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="js/cufon-yui.js" type="text/javascript"></script>
    <script src="js/cufon-replace.js" type="text/javascript"></script>
    <script src="js/Schneidler_Md_BT_400.font.js" type="text/javascript"></script>
    <script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
    <!--used for the rotating images that show up if the user doesn't have flash-->
    <script type="text/javascript" src="/assets/js/jquery.cycle.lite.js"></script>
    to this:
    <link href="../style.css" rel="stylesheet" type="text/css" />
    <link href="../layout.css" rel="stylesheet" type="text/css" />
    <script src="../js/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="../js/cufon-yui.js" type="text/javascript"></script>
    <script src="../js/cufon-replace.js" type="text/javascript"></script>
    <script src="../js/Schneidler_Md_BT_400.font.js" type="text/javascript"></script>
    <script src="../Scripts/swfobject_modified.js" type="text/javascript"></script>
    <!--used for the rotating images that show up if the user doesn't have flash-->
    <script type="text/javascript" src="../assets/js/jquery.cycle.lite.js"></script>
    Nancy O.

Maybe you are looking for

  • PIctures and music will not come off my iPhone.

    I am trying to clean up my iPhone. I want to remove some old pictures but they will not come off. I have tried removing them from iTunes. I unclicked sync photos and did a sync but they will not remove. They are pictures I uploaded from my computer m

  • Battey wont charge and I cant figure out how to reset my i pod.

    If any one can help me. Im new to Mac and Ipods. my I pod worked earlier today and then it shows the apple support sad face and the flashes to a battery with a lighting bolt. I have tried to reset it with the support page info but I am totally stuck

  • Oracle forms 9i and C language

    Hi, I'm not able to use user-exits written in C language with oracle 9i in UNIX_HP environment. From the URL with a form without user exits it is ok, but if I start with a form with user-exits I have the message FRM-40800. With oracle forms 4.5 it is

  • JSTL, MySQL, Tomcat sql:query error

    Hi to everyone... This is my first post, but since im employed now as a java developer ill be here regulary. Right now im trying to use the JSTL to make some simple sql selects in my JSPs.... Here�s the JSP code: <%@ page language="java" import="java

  • Calculate sum of under estimates

    I have a 2008 r2 cube with 2 measures EstmatedTime and ActualTime and a date dimension.  I need to calculate the sum of the under estimates.  So if my estimated hours on the 1st, 2nd and 3rd are 10, 10, 10  and my actual hours are 11, 12, 7, I need t