Article View: borland.public.jbuilder.java.language
Article #7684Re: URL Hell!!! Please Help...
From: Nabin Thomas
Date: Sat, 26 May 2001 05:23
Date: Sat, 26 May 2001 05:23
115 lines
4438 bytes
4438 bytes
T dont think you can do this directly.
You need to check periodically and check whether the file hase changed since last load and
reload the file.
An optimal way will be to do this in activate event f the frame
Bernie wrote:
> The basic application listed below will load an html page from
> disk into a JEditorPane after clicking the "Get Page" button.
> The problem is, if I change the file named word.html, the
> changes are not displayed in the JEditorPane. If I change
> the file word.html, what do I have to do have the updated
> page loaded into the JEditorPane?
>
> -Thanks
>
> package viewurl;
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
> import javax.swing.event.*;
> import java.io.*;
> import java.net.*;
>
> public class Frame1 extends JFrame {
> JPanel contentPane;
> JScrollPane jScrollPane1 = new JScrollPane();
> JEditorPane jEditorPane1 = new JEditorPane();
> JButton jButton1 = new JButton();
> static String userDir = System.getProperty("user.dir");
>
> /**Construct the frame*/
> public Frame1() {
> enableEvents(AWTEvent.WINDOW_EVENT_MASK);
> try {
> jbInit();
> }
> catch(Exception e) {
> e.printStackTrace();
> }
> }
> /**Component initialization*/
> private void jbInit() throws Exception {
>
> //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your
> Icon]")));
> contentPane = (JPanel) this.getContentPane();
> contentPane.setLayout(null);
> this.setSize(new Dimension(400, 300));
> this.setTitle("Frame Title");
> jScrollPane1.setBounds(new Rectangle(9, 9, 381, 234));
> jEditorPane1.setEditable(false);
> jEditorPane1.addHyperlinkListener(new
> javax.swing.event.HyperlinkListener() {
> public void hyperlinkUpdate(HyperlinkEvent e) {
> jEditorPane1_hyperlinkUpdate(e);
> }
> });
> jButton1.setText("Get Page");
> jButton1.setBounds(new Rectangle(146, 256, 100, 27));
> jButton1.addActionListener(new java.awt.event.ActionListener() {
> public void actionPerformed(ActionEvent e) {
> jButton1_actionPerformed(e);
> }
> });
> contentPane.add(jScrollPane1, null);
> contentPane.add(jButton1, null);
> jScrollPane1.getViewport().add(jEditorPane1, null);
> }
> /**Overridden so we can exit when window is closed*/
> protected void processWindowEvent(WindowEvent e) {
> super.processWindowEvent(e);
> if (e.getID() == WindowEvent.WINDOW_CLOSING) {
> System.exit(0);
> }
> }
>
> void jEditorPane1_hyperlinkUpdate(HyperlinkEvent e) {
>
> }
>
> void jButton1_actionPerformed(ActionEvent e) {
>
> try {
> jEditorPane1.setPage("file:" + userDir + "/word.html");
> jEditorPane1.revalidate();
> jEditorPane1.repaint();
> }
> catch (IOException ex) {
> ex.printStackTrace(System.err);
> }
>
> }
>
> }
--
***********************************
***************************************************
******************* Web Card **********************
***************************************************
Name : Nabin Thomas
e-mail : nabinthomas@hotmail.com
Web : http://nabin.terrashare.com
Feel free to contact me thru e-mail or MSN Mssenger
if required but DONOT SPAM
***************************************************
***********************************
Technical Details
Message-ID:
<3B0F3DBA.B17F25A1@hotmail.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!dispose.news.demon.net!demon!grolier!fr.usenet-edu.net!usenet-edu.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnewsReferences:
<3B0D7FF7.3F03D890@att.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,4fe5d4cf1e2c0d64 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-05-25 22:52:02 PST Message-ID: <3B0F3DBA.B17F25A1@hotmail.com> Date: Sat, 26 May 2001 10:53:07 +0530 From: Nabin Thomas <nabinthomas@hotmail.com> X-Mailer: Mozilla 4.75 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: Re: URL Hell!!! Please Help... References: <3B0D7FF7.3F03D890@att.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 202.9.167.237 X-Trace: dnews 990855210 202.9.167.237 (25 May 2001 22:33:30 -0700) Lines: 118 Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!dispose.news.demon.net!demon!grolier!fr.usenet-edu.net!usenet-edu.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews