Same Image every time in JTextField with HTMLEditorKit and HTMLDocument

Hi all
I have a JTextPane with HTMLEditorKit as editorkit and HTMLDocument as document. I am trying to load an html file into the text pane. the html file contains image. When loading first time it is shown perfectly. After I change the image file with other file with the same name(overwrite it) and trying to load the html file again,the image is the first time loaded image. As i think the image is kept somewhere in "cash" or kind of that. But I need to refresh the html every time it is loaded and not to read from "cash".
And code which i use:
package client.temp;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
public class TestPanel extends JPanel {
public TestPanel(File htmlFile) {
JTextPane textPane = new JTextPane();
JScrollPane scrollPane = new JScrollPane();
HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
HTMLDocument htmlDocument = new HTMLDocument();
setLayout(new BorderLayout());
scrollPane.getViewport().add(textPane, null);
add(scrollPane, BorderLayout.CENTER);
URL baseUrl = null;
try {
baseUrl = htmlFile.getParentFile().toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
htmlDocument.setBase(baseUrl);
textPane.setEditorKit(htmlEditorKit);
try {
FileInputStream fi = new FileInputStream(htmlFile);
InputStreamReader isr = new InputStreamReader(fi, "UTF8");
BufferedReader r = new BufferedReader(isr);
htmlEditorKit.read(r, htmlDocument, 0);
r.close();
isr.close();
fi.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (BadLocationException e) {
e.printStackTrace();
textPane.setDocument(htmlDocument);
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton b = new JButton();
b.setText("push");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
TestPanel panel = new TestPanel(new File("c:\\temp\\temp.html"));
JFrame fShow = new JFrame();
fShow.getContentPane().setLayout(new BorderLayout());
fShow.getContentPane().add(panel, BorderLayout.CENTER);
fShow.setSize(800, 600);
fShow.setVisible(true);
frame.getContentPane().add(b);
frame.pack();
frame.setVisible(true);
and here is the html file structure of my temp.html file
<html>
<body>
<p>
<img src='image01.jpg'>
</p>
</body>
</html>
the folder in which the temp.html located (in my case c:\\temp\\) contains image01.jpg file too.
The piece above works correctly when clicking on the button first time.i.e. shows the image01.jpg correctly. After closing the showing frame fShow(not exiting application) and replacement of the image01.jpg by other file named image01.jpg, but with other content and clicking button again shows the first image again.If I exit the application and start again the picture is shown correctly.
I need this because I am getting images from database while the template is same always.
Thanks in advance.

URL baseUrl = null;
try {
baseUrl = htmlFile.getParentFile().toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
htmlDocument.setBase(baseUrl);All you want is to defeat the cache. You could do it using random number generation.
String newURL = htmlFile.getParentFile().toURL().toString();
String rand = "rand="+new java.utl.Random().nextLong();
if ( newURL.indexOf("?")>=0)
newURL +="&"+rand;
else
newURL +="?"+rand;
baseURL = new URL(newURL);
htmlDocument.setBase(baseURL);
This will ensure that u are using different url everytime.(well mostly!)

Similar Messages

  • Tried to reinstall OSX Mountain Lion 10.8.4 and every time i start with the installation i get a requested time out message, had to shut down my MacBook Pro retina. Now when i start up it automatically start internet recovery

    tried to reinstall OSX Mountain Lion 10.8.4 and every time i start with the installation i get a requested time out message, had to shut down my MacBook Pro retina. Now when i start up it automatically start internet recovery for two ouers. After the internet recovery the same problem with reinstalling OSX message

    Gave up on the GUI.  This script derived from http://blog.netnerds.net/2012/07/os-x-how-to-setup-nat-on-lion-and-mountain-lion / seems to work for me:
    gwdev=en0 # This is my WiFi connection (has Internet connection)
    targetdev=en1 # This is the USB to Ethernet adapter (to give Internet connection)
    /sbin/ifconfig $targetdev down
    /sbin/ifconfig bridge0 create
    /sbin/ifconfig bridge0 up
    /sbin/ifconfig bridge0 addm $gwdev
    /sbin/ifconfig bridge0 $HOST_ADDR
    /sbin/route add default -interface bridge0 -ifscope bridge0 -cloning
    /usr/sbin/sysctl -w net.inet.ip.forwarding=1
    /sbin/ipfw add 100 divert natd ip from any to any via $gwdev
    /usr/sbin/natd -interface $gwdev -use_sockets -same_ports -unregistered_only -dynamic -clamp_mss -enable_natportmap -natportmap_interface $targetdev

  • I have set up a Netgear dual band modem which works well with the iPhone and an older MacBook, but with this brand new MacBook it asks for a password every time I reopen the computer and open safari. Is it Lion?

    I have set up a Netgear dual band modem which works well with the iPhone and an older MacBook, but with this brand new MacBook it asks for a password every time I reopen the computer and open safari. As you can imagine this is very annoying. It says I am not connected to the internet and offers me a choice of nearby networks including mine and then asks for a password when I select it. Why does it do this with our new MacBooks (also with my son's brand new one) and not with the iPhone, iPad and older MacBook? They happily automatically connect to our network after entering the password just the once.

    Sig, I appreciate you trying to be helpful. I have no idea what issues you were having or what issue exactly pgrounds has been having. Your assumption that everyone's set up is the same as yours is false however. There are many many documented WiFi issues that are a result of Lion installs. Many have been solved by 10.7.1 and 10.7.2. Others have been solved by a large variety of work arounds. Others have not had their issues solved yet.
    I am one of those. I have an IT background, and I spent the better of five hours digging up workarounds and attempting all of them. For the benefit oh anyone who is having similar issues, I have posted links to all of those workarounds here. None of them worked in my case, but hopefully they will help pgrounds or others.
    So, once again, if you have a new idea, I'd love to here it. But if it has already been posted in one of these links, it's not helpful, let it go.
    http://osxdaily.com/2011/07/22/wifi-dropping-in-os-x-lion-fixes/
    http://osxdaily.com/2011/11/06/lion-wi-fi-problems-solution-mac/
    http://blog.chron.com/techblog/2011/09/want-to-really-repair-permissions-on-your -mac-try-this/

  • Adobe Media Encoder for Premiere Pro CS4 stops working on the same frame every time...

    I currently have Adobe Premiere Pro CS4 and have never had these issues exporting before. My timeline is less than 3 minutes long, but it does deal with multiple big files. It rendered perfectly and it plays perfectly in the timeline. When I try to export it using Media Encoder, however, it freezes at the same frame every time (which is actually only a few seconds in!) and then crashes, so that I have to force quit. I have tried exporting it as many different codecs and the problem persists... same frame. I tried creating a new project entirely and whipping together a few titles and exporting that to see if it just won't export anything at all. The new project exported just fine, however, which I suppose is good news. But yeah, my work on that other project is very important to me and I reallllly want to export it. Please help!

    Hi Jim! Thank you for your reply. I think you are right -- and that it lies in the audio somehow!
    It turns out that if I choose to only export the video, and uncheck audio, it will export very well and smoothly. That's great news for me!
    However, now I am trying to work out how to get the audio exported without issues. I actually had the idea of just playing the audio in the timeline and recording it via Stereo Mix, but my Windows 7 driver has Stereo Mix disabled, so it's back to square one. Any ideas of what I can do about the corrupted audio not exporting, which works fine when played in the timeline?

  • When i click on my external hard drive the screen goes dark and a msg pops up saying i have to shut down my computer by holding the power button and then restart it. when i do that i get the same result every time. it worked perfectly last night..

    when i click on my external hard drive the screen goes dark and a msg pops up saying i have to shut down my computer by holding the power button and then restart it. when i do that i get the same result every time. it worked perfectly last night..

    These instructions must be carried out as an administrator. If you have only one user account, you are the administrator.
    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Ifou don't see any reports listed, but you know there was a panic, you may have chosen Diagnostic and Usage Messages from the log list. Choose DIAGNOSTIC AND USAGE INFORMATION instead.
    In the Console window, select
              DIAGNOSTIC AND USAGE INFORMATION ▹ System Diagnostic Reports
    (not Diagnostic and Usage Messages) from the log list on the left. If you don't see that list, select
              View ▹ Show Log List
    from the menu bar.
    There is a disclosure triangle to the left of the list item. If the triangle is pointing to the right, click it so that it points down. You'll see a list of reports. A panic report has a name that begins with "Kernel" and ends in ".panic". Select the most recent one. The contents of the report will appear on the right. Use copy and paste to post the entire contents—the text, not a screenshot.
    If you don't see any reports listed, but you know there was a panic, you may have chosen Diagnostic and Usage Messages from the log list. Choose DIAGNOSTIC AND USAGE INFORMATION instead.
    In the interest of privacy, I suggest that, before posting, you edit out the “Anonymous UUID,” a long string of letters, numbers, and dashes in the header of the report, if it’s present (it may not be.)
    Please don’t post other kinds of diagnostic report.
    I know the report is long, maybe several hundred lines. Please post all of it anyway.

  • I'm trying to update my Photoshop CS5, but continue to receive the same problem every time. The application manager update dialogue box simply states "some updates failed to install." There's no specific error code, but a link to contact support for furth

    I'm trying to update my Photoshop CS5, but continue to receive the same problem every time. The application manager update dialogue box simply states "some updates failed to install." There's no specific error code, but a link to contact support for further assistance. It doesn't take me to customer support, but does take me to a screen which states. "Error "This serial number is not for a qualifying product." I've checked my account and the product serial number is associated with my account., so I don't see any problem.  I have not been able to find a resolution to this problem, so I hope that someone can point me in the right direction.  Thank you!

    update directly, Product updates

  • This is my 4th revoulution..same problems every time

    This is my 4th phone (refurbished) and I keep having the same issues every time. About 3-5 days after activating the phone, I get dropped calls, people sound like they're under water, black screen, freezes up, shuts down..and many many more, I've been dealing with "tech" support only to have ANOTHER revolution sent to me. I'm wondering if anyone else has been having the same or similar problem? Any suggestions on how to handle this and possibly getting different model phone..help because I'm ready to throw it across the room. it's very frustrating and I'm fed up with the phone and Verizon it's self. any suggestions would be much appreciated. Thank You

    Try reverting to automatic updating if you are manually doing it, or vica versa. Also, make sure your headphones are working by testing with another device. Alternatively, the headphone port may be clogged with gunk. Get a Q-tip or something appropriate and put a dab of metholayted spirits on it. Clean the contacts of the port by inserting it and rotating several times. Try playing again.
    Hope this helps.

  • Same Tunes Every Time

    I've had my iPod Touch for about a month now. As I look at iTunes when my iPod Touch synches with my MacBook Pro laptop, it seems that over and over it needs to update the same 7-10 songs. Same songs every time. And I haven't even played them. There should not be any reason to update these songs, but they are synched every time.
    Anyone else seeing this?
    Neal

    If just replacing the artwork on the offending songs doesn't fix it, I read from another user here that you can try changing the iPod to manual mode, then back to auto-sync. Not sure if that actually works though, but seems harmless.

  • How can I save to the same map every time when printing pdfs?

    How can I save to the same map every time when printing pdfs?
    Finder points to the document map even when I chose a different map recently.
    I often print series of pdfs from the print dialog box, I'd like to choose the map to save to and then have all subsequent pdf prints automatically directed to the same map until I decide otherwise.

    that link seems to be broken right now:
    403 Error - Forbidden  - No cred, dude.

  • Why do I lose the playlist I have created on my ipod touch every time I sync with itunes?

    Why do I lose the playlists I havae created on my ipod touch every time I sync with itunes?

    If I go to contacts for a split second the + sign is there and then it goes. Also on Mail,Contacts, Calendars in Settings opens and then in a split second goes back to desk top. As I lost my earlier ipod touch had to change password to gmail but cant change it on my ipod as  cant get to settings! Help please?

  • How to automate saving the same image multiple times?

    Hello. I wish to save the same image multiple times in a folder... is there a way to automate this function? I also need the flexibility of determining the starting number in this image sequence. Thanks.

    Good day!
    I would recommend asking for help over at
    Photoshop Scripting
    And going into more detail about what you want to achieve (maybe post a screenshot, diagram, mock-up to illustrate it).
    Regards,
    Pfaffenbichler

  • Please help! I am trying to change my Apple Id that used to be my mother to Mine- Every time i have it changed and i go and try and do an update it continues to ask for her old password. I really need help with this!

    Please help! I am trying to change my Apple Id that used to be my mother to Mine- Every time i have it changed and i go and try and do an update it continues to ask for her old password. I really need help with this!

    Phil0124 wrote:
    Apps downloaded with an Apple ID are forever tied to that Apple ID and will always require it to update.
    The only way around this is to delete the apps that require the other Apple ID and download them again with yours.
    Or simply log out of iTunes & App stores then log in with updated AppleID.

  • Why do I get this message every time I travel with my laptop and then return home: To improve reliability, Time Machine must create a new backup for you.

    Why do I get this message every time I travel with my laptop and then return home: "To improve reliability, Time Machine must create a new backup for you."
    I get this on my new MacBook Air, but never got it on my old MacBook Pro.
    Thanks!

    See #C13 in Time Machine - Troubleshooting.

  • HI ALL SINCE TWO DAYS I AM DOWNLOADING VIBER BUT I AM NOT HAVING MY ACCESS CODE AND EVERY TIME I DELETE THE APPLICATION AND DOWNLOADING IT AGAIN BUT ALWAYS THE SAME RESULT PLEASE I NEED YOUR HELP FOR THE ACCESS CODE.MY PHONE NUMBER IS 0022996969896.THANKS

    HI ALL SINCE TWO DAYS I AM DOWNLOADING VIBER BUT I AM NOT HAVING MY ACCESS CODE AND EVERY TIME I DELETE THE APPLICATION AND DOWNLOADING IT AGAIN BUT ALWAYS THE SAME RESULT PLEASE I NEED YOUR HELP FOR THE ACCESS CODE.MY PHONE NUMBER IS 0022996969896.THANKS IN ADVANCE

    try this website this should help you http://helpme.viber.com/index.php?/Knowledgebase/List/Index/1/iphone

  • HT1390 My movie crashes/stops half way through at the same place every time. I would like to watch the whole film... who do I get to sort this out? thanks

    My movie crashes/stops half way through at the same place every time. I would like to watch the whole film... who do I get to sort this out? thanks!

    Click Support at the top of this page, then click the link under Contact Us

Maybe you are looking for