Home arrow static arrow Java Programming [Archive] - JEditorPane problem
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - JEditorPane problem
This topic has 9 replies on 1 page.

Posts:1,206
Registered: 4/19/02
JEditorPane problem  
May 25, 2004 8:25 AM



 
I need to display a web page into a JEditorPane. If i only use JEditorPane constructor like new JEditorPane(initialURL) the page is loading twice.. the user can't see it, but it appear on the server log (and i can't let the program load it twice, cause the perl code inside is executing twice). So i found another way to load it by using the read function. If i only use the read function without HTMLDocument and HTMLEditorKit the page is loading but only in text not in html. So i found a way to do it, but i'm not able to run the code without error. I maked somes search on google and others place and find nothing helpfull...

here's my code
    public JBrowser(String initialURL, String title, Dimension dim,        boolean basApplet)    {        super(title);        JScrollPane scrollPane = null;        try        {            bClose = new JButton("Fermer");            bClose.addActionListener(this);            theBigOne = new JPanel(new GridLayout(2, 1));            htmlPane = new JEditorPane();            HTMLEditorKit kit = new HTMLEditorKit();            HTMLDocument htmlDoc = new HTMLDocument();                htmlPane.setEditorKit(kit);            htmlPane.setDocument(htmlDoc);                       try            {                htmlPane.read((new URL(initialURL)).openConnection()                    .getInputStream(), htmlDoc);                      }            catch (MalformedURLException m)            {                System.out.println(m.getMessage());            }                       htmlPane.setEditable(false);            htmlPane.addHyperlinkListener(this);            htmlPane.setBorder(null);             scrollPane = new JScrollPane(htmlPane);            if (basApplet)            {                htmlPane.addPropertyChangeListener(this);                theBigOne.setBackground(new Color(192, 192, 192));                theBigOne.add(scrollPane);                getContentPane().add(theBigOne);            }        }        catch(Exception ioe)        {            //warnUser("Can't build HTML pane for " + initialURL + ": " + ioe);            System.out.println(ioe.getMessage());        }           Dimension screenSize = getToolkit().getScreenSize();        setBounds((screenSize.width - dim.width) / 2, (screenSize.height            - dim.height) / 2, dim.width, dim.height);        setResizable(false);               if (!basApplet)        {              getContentPane().add(scrollPane, BorderLayout.CENTER);            getContentPane().add(bClose, BorderLayout.SOUTH);            setVisible(true);        }            }


here's the error

i got a NullPointerException on this line: getContentPane().add(scrollPane, BorderLayout.CENTER);

and i dont have problem with this line with my code before (without the HTMLEditorKit)

So if someone could resolve my problem, or give me a possibility to load a html page only 1 time into a JEditorPane or another component, i dont care

thx for help
 

Posts:4,906
Registered: 23/07/02
Re: JEditorPane problem  
May 25, 2004 9:56 AM (reply 1 of 9)



 
How about
JEditorPane jep = new JEditorPane();jep.setPage(myURL);
?
 

Posts:1,206
Registered: 4/19/02
Re: JEditorPane problem  
May 25, 2004 10:12 AM (reply 2 of 9)



 
it was my fist attemp, but for a unknow reason the page is loading twice with this way...
and i can't load the page twice, cause he have some server side code on this page that can't be executing twice

thx
 

Posts:1,206
Registered: 4/19/02
Re: JEditorPane problem  
May 25, 2004 10:33 AM (reply 3 of 9)



 
but it work without error if i use:
    public JBrowser(String initialURL, String title, Dimension dim,        boolean basApplet)    {        super(title);        JScrollPane scrollPane = null;        try        {            bClose = new JButton("Fermer");            bClose.addActionListener(this);            theBigOne = new JPanel(new GridLayout(2, 1));            htmlPane = new JEditorPane(initialURL);                       htmlPane.setEditable(false);            htmlPane.addHyperlinkListener(this);            htmlPane.setBorder(null);             scrollPane = new JScrollPane(htmlPane);            if (basApplet)            {                htmlPane.addPropertyChangeListener(this);                theBigOne.setBackground(new Color(192, 192, 192));                theBigOne.add(scrollPane);                getContentPane().add(theBigOne);            }        }        catch(Exception ioe)        {            //warnUser("Can't build HTML pane for " + initialURL + ": " + ioe);            System.out.println(ioe.getMessage());        }           Dimension screenSize = getToolkit().getScreenSize();        setBounds((screenSize.width - dim.width) / 2, (screenSize.height            - dim.height) / 2, dim.width, dim.height);        setResizable(false);               if (!basApplet)        {              getContentPane().add(scrollPane, BorderLayout.CENTER);            getContentPane().add(bClose, BorderLayout.SOUTH);            setVisible(true);        }            }

but the page is loading twice don't know why

and if i'm using:

    public JBrowser(String initialURL, String title, Dimension dim,        boolean basApplet)    {        super(title);        JScrollPane scrollPane = null;        try        {            bClose = new JButton("Fermer");            bClose.addActionListener(this);            theBigOne = new JPanel(new GridLayout(2, 1));            htmlPane = new JEditorPane();                       try            {                htmlPane.read((new URL(initialURL)).openConnection()                    .getInputStream(), htmlPane.getDocument());                      }            catch (MalformedURLException m)            {                System.out.println(m.getMessage());            }                       htmlPane.setEditable(false);            htmlPane.addHyperlinkListener(this);            htmlPane.setBorder(null);             scrollPane = new JScrollPane(htmlPane);            if (basApplet)            {                htmlPane.addPropertyChangeListener(this);                theBigOne.setBackground(new Color(192, 192, 192));                theBigOne.add(scrollPane);                getContentPane().add(theBigOne);            }        }        catch(Exception ioe)        {            //warnUser("Can't build HTML pane for " + initialURL + ": " + ioe);            System.out.println(ioe.getMessage());        }           Dimension screenSize = getToolkit().getScreenSize();        setBounds((screenSize.width - dim.width) / 2, (screenSize.height            - dim.height) / 2, dim.width, dim.height);        setResizable(false);               if (!basApplet)        {              getContentPane().add(scrollPane, BorderLayout.CENTER);            getContentPane().add(bClose, BorderLayout.SOUTH);            setVisible(true);        }            }


and it this way it work, but it's loading in plain text
 

Posts:1,206
Registered: 4/19/02
Re: JEditorPane problem  
May 25, 2004 10:44 AM (reply 4 of 9)



 
and with the method that display text without error, if i add this line after the read
htmlPane.setContentType("text/html");

i have a white page with nothing
 

Posts:1,206
Registered: 4/19/02
Re: JEditorPane problem  
May 25, 2004 11:15 AM (reply 5 of 9)



 
I added 1 more duke
thx
 

Posts:1,206
Registered: 4/19/02
Re: JEditorPane problem  
May 25, 2004 1:25 PM (reply 6 of 9)



 
nobody?
 

Posts:1,206
Registered: 4/19/02
Re: JEditorPane problem  
May 26, 2004 8:18 AM (reply 7 of 9)



 
somebody asnwer me in another forum...
im leaving this topic
thx
 

Posts:8
Registered: 4/23/99
Re: JEditorPane problem  
Aug 2, 2004 11:33 AM (reply 8 of 9)



 
Please post the answer
 

Posts:14,142
Registered: 99-04-02
Re: JEditorPane problem  
Aug 2, 2004 11:55 AM (reply 9 of 9)



 
no, you can't leave now...

I don't know why it's doing this, but are you sure that it's a page that JEditorPane can actually handle displaying? JEditorPane can only show HTML 3.2 documents, and that's pretty old. Probably a large protion of web sites won't work or work correctly in JEditorPane. It's really too bad too, since Java put this capablility in since Java 1.2, but they haven't maintained it to keep up with browsers... And yes, I know it's not a simple task to keep up with.
 
This topic has 9 replies on 1 page.