How to open a URL from a Swing Component?

Discussion in 'Java' started by Bengan, Jul 28, 2003.

  1. Bengan

    Bengan Guest

    Hi,

    I have a Frame and want to be able to open an URL(HTML page) with a button
    click. I mean like you do with the showDocument method under AppletContext.
    But i cant find any method that does that.

    Best Regards
    Bengan
     
    Bengan, Jul 28, 2003
    #1
    1. Advertising

  2. Do you want to

    1. use the platform browser to show the document or

    2. use a Java panel to open the URL?

    For 1, you will have to launch the browser with
    Runtime.getRuntime().exec(). You can launch the external browser
    program with URL as the argument. Some platforms allow you to simply
    run the URL and the OS will launch the default browser (e.g. MS
    Windows - Runtime.getRuntime().exec("http://www.google.com");

    REF:
    http://java.sun.com/j2se/1.3/docs/api/java/lang/Runtime.html#exec(java.lang.String)

    For 2, you can use javax.swing.JEditorPane, add it to your frame,set
    the content type to "text/html" and use
    setPage("http://www.google.com");

    REF:
    http://java.sun.com/j2se/1.3/docs/api/javax/swing/JEditorPane.html
    http://java.sun.com/docs/books/tutorial/uiswing/components/simpletext.html#editorpane

    HTH,
    sandip


    "Bengan" <> wrote in message news:<3f24861f$0$305$>...
    > Hi,
    >
    > I have a Frame and want to be able to open an URL(HTML page) with a button
    > click. I mean like you do with the showDocument method under AppletContext.
    > But i cant find any method that does that.
    >
    > Best Regards
    > Bengan
     
    Sandip Chitale, Jul 28, 2003
    #2
    1. Advertising

  3. Bengan

    Roedy Green Guest

    On 28 Jul 2003 02:10:39 GMT, "Bengan" <> wrote or
    quoted :

    >I have a Frame and want to be able to open an URL(HTML page) with a button
    >click. I mean like you do with the showDocument method under AppletContext.
    >But i cant find any method that does that.


    You could do an HTTP GET, retrieve the message, then feed it to a
    output = new JEditorPane();
    output.setContentType("text/html");
    output.setEditable(false);

    Any pray Swing is smart enough to render your html.

    See http://mindprod.com/jgloss/htmlrendering.html for your other
    options.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jul 29, 2003
    #3
  4. Bengan

    Roedy Green Guest

    Roedy Green, Jul 29, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Big Daddy

    Java 1.2 Swing vs. Java 1.5 Swing

    Big Daddy, Apr 15, 2005, in forum: Java
    Replies:
    2
    Views:
    509
    Pete Barrett
    Apr 16, 2005
  2. mkrause
    Replies:
    0
    Views:
    680
    mkrause
    May 6, 2005
  3. lizard
    Replies:
    0
    Views:
    1,784
    lizard
    Jan 30, 2006
  4. S.T
    Replies:
    2
    Views:
    593
  5. Knute Johnson

    Swing is dead! Long live Swing.

    Knute Johnson, Feb 16, 2012, in forum: Java
    Replies:
    32
    Views:
    3,821
    Daniel Pitts
    Feb 29, 2012
Loading...

Share This Page