Hypertext in java

Discussion in 'Java' started by Marte Brenne, Apr 23, 2004.

  1. Marte Brenne

    Marte Brenne Guest

    Hi!

    Can anyone please tell me if it's possible to use hypertext in java? I
    have designed a user interface, and I want something to happen when
    you click on some Strings. Because it's a lot of text that I want to
    make clickable, I can't use buttons.

    Thank you very much in advance!
     
    Marte Brenne, Apr 23, 2004
    #1
    1. Advertising

  2. On 23 Apr 2004 02:18:43 -0700, Marte Brenne wrote:

    > Can anyone please tell me if it's possible to use hypertext in java?


    As in HTML? Yes. Swing components accept it.
    <http://www.physci.org/launcher.jsp#JAddPane>

    >I
    > have designed a user interface, and I want something to happen when
    > you click on some Strings. Because it's a lot of text that I want to
    > make clickable,


    Over 10 Meg eh?!?
    What happened when you tried it?

    >...I can't use buttons.


    A JButton will accept HTML, lots of it.
    but that will be a BIG button. ;-)

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Apr 23, 2004
    #2
    1. Advertising

  3. Marte Brenne

    Pimousse Guest

    > Can anyone please tell me if it's possible to use hypertext in java? I
    > have designed a user interface, and I want something to happen when
    > you click on some Strings. Because it's a lot of text that I want to
    > make clickable, I can't use buttons.


    use HTML hyperlinks
    create a JEditorPane myEditorPane

    do
    myEditorPane.setEditorKit(new HTMLEditorKit());

    then
    myEditorPane.addHyperLinkListener(this);

    after you can put your html text in :
    myEditorPane.setText(myTextInHTML);

    you'll have to implement the following method :
    public void hyperlinkUpdate(HyperlinkEvent e){

    // you'll define here the behaviour when clicking an hyperlink
    }

    @++
    Pimousse
     
    Pimousse, Apr 23, 2004
    #3
  4. Marte Brenne

    Marte Brenne Guest

    Andrew Thompson <> wrote in message news:<ufhaeqm50zci.rk4ohov2arig$>...
    > On 23 Apr 2004 02:18:43 -0700, Marte Brenne wrote:
    >
    > > Can anyone please tell me if it's possible to use hypertext in java?

    >
    > As in HTML? Yes. Swing components accept it.
    > <http://www.physci.org/launcher.jsp#JAddPane>
    >
    > >I
    > > have designed a user interface, and I want something to happen when
    > > you click on some Strings. Because it's a lot of text that I want to
    > > make clickable,

    >
    > Over 10 Meg eh?!?
    > What happened when you tried it?
    >
    > >...I can't use buttons.

    >
    > A JButton will accept HTML, lots of it.
    > but that will be a BIG button. ;-)


    Thank you very much for your answer! I probably didn't express myself
    clearly. I don't want to use HTML, I just want to make some String's
    clickable. I have a paragraph with words - some individual words and
    some groups of words (separated with commas). Depending on which
    word/group of words that is clicked, something is going to happen
    (e.g. a JTree with some nodes are going to get new nodes).

    If you (or someone else) know if this is possible to do, I will
    appreciate it a lot if you let me know. Thank you very much in advance
    :)

    PS! If it makes a difference, my program is yet an application, and no
    applet, but I will perhaps change it into an applet.
     
    Marte Brenne, Apr 26, 2004
    #4
  5. Marte Brenne

    Rogan Dawes Guest

    Marte Brenne wrote:

    > Andrew Thompson <> wrote in message news:<ufhaeqm50zci.rk4ohov2arig$>...
    >
    >>On 23 Apr 2004 02:18:43 -0700, Marte Brenne wrote:
    >>
    >>
    >>>Can anyone please tell me if it's possible to use hypertext in java?

    >>
    >>As in HTML? Yes. Swing components accept it.
    >><http://www.physci.org/launcher.jsp#JAddPane>
    >>
    >>>I
    >>>have designed a user interface, and I want something to happen when
    >>>you click on some Strings. Because it's a lot of text that I want to
    >>>make clickable,

    >>
    >>Over 10 Meg eh?!?
    >>What happened when you tried it?
    >>
    >>
    >>>...I can't use buttons.

    >>
    >>A JButton will accept HTML, lots of it.
    >>but that will be a BIG button. ;-)

    >
    >
    > Thank you very much for your answer! I probably didn't express myself
    > clearly. I don't want to use HTML, I just want to make some String's
    > clickable. I have a paragraph with words - some individual words and
    > some groups of words (separated with commas). Depending on which
    > word/group of words that is clicked, something is going to happen
    > (e.g. a JTree with some nodes are going to get new nodes).
    >
    > If you (or someone else) know if this is possible to do, I will
    > appreciate it a lot if you let me know. Thank you very much in advance
    > :)
    >
    > PS! If it makes a difference, my program is yet an application, and no
    > applet, but I will perhaps change it into an applet.


    JEditorPane supports HTML, and you can register a Listener that will be
    notified when you click on a link. You just need to make the JEditorPane
    readonly, otherwise a click on a link will be interpreted as trying to
    edit the text of the link.

    Hope this helps.

    Regards,

    Rogan
    --
    Rogan Dawes
    nntp_AT_dawes*DOT*za-DOT-net
     
    Rogan Dawes, Apr 26, 2004
    #5
  6. Marte Brenne

    Roedy Green Guest

    On 26 Apr 2004 01:10:18 -0700, (Marte Brenne)
    wrote or quoted :

    >Thank you very much for your answer! I probably didn't express myself
    >clearly. I don't want to use HTML, I just want to make some String's
    >clickable. I have a paragraph with words - some individual words and
    >some groups of words (separated with commas). Depending on which
    >word/group of words that is clicked, something is going to happen
    >(e.g. a JTree with some nodes are going to get new nodes).


    Just how complicated is this html? If in is very simple you could
    convert it yourself to a list of tokens. with x,y, font, colour and
    text, and delegate what to do if user clicks this.

    Then you do render this yourself in your mini browser in a Canvas or
    Jpanel with custom paint.

    You field the Mouse click event, and figure out which thing he
    clicked, and call the appropriate method.

    For a huge document, you need to scroll, and avoid rendering outside
    theclipregion.

    You could also use a hanging moss algorithm to figure out which
    element was clicked rather than by comparing against every possibility
    linearly.

    see http://mindprod.com/jgloss/canvas.html
    see http://mindprod.com/jgloss/paint.html
    See http://mindprod.com/jgloss/hangingmoss.html


    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Apr 26, 2004
    #6
  7. Marte Brenne

    Roedy Green Guest

    On Mon, 26 Apr 2004 20:28:07 GMT, Roedy Green
    <> wrote or quoted :

    >Then you do render this yourself in your mini browser in a Canvas or
    >Jpanel with custom paint.


    Don't consider this unless the other solution letting Swing render for
    you and detect the link clicks proves hopelessly slow. You just need
    to set up some dummy links in your html for the magic words.


    The other solution will be orders of magnitude easier to implement
    than mine.


    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Apr 26, 2004
    #7
  8. On Mon, 26 Apr 2004 20:28:07 GMT, Roedy Green wrote:

    >> I don't want to use HTML, I just want to make some String's
    >> clickable.


    ....errm. OoooK.

    The thing is, the easiest way to
    'make Strings clickable' is to
    ...write them as HTML and add an
    HyperLinkListener.

    Once something is clicked, the program
    can do the appropriate actions.

    There _are_ other ways to do it,
    but I suspect that is the easiest.

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Apr 26, 2004
    #8
  9. On 26 Apr 2004 01:10:18 -0700, Marte Brenne wrote:

    [something screwy was happening with my feed
    to usenet so that I received Roedy's response
    to you before your post, so I only just saw
    this bit..]

    > PS! If it makes a difference, my program is yet an application, and no
    > applet, but I will perhaps change it into an applet.


    No. I was basing that purely on
    'Swing does easy (quick'n'dirty) HTML support'.

    It sounds perfect for your application..

    ...put your text inside a JEDitorPane in
    HTML format, use a style sheet to remove the
    link underlines as well if you like.

    Connect am HyperLinkListener to the JEP
    and do whatever you like with the resultant
    events detected.

    Applet or App., does not matter.

    See how easily you can get a
    'functional' browser in this example..
    <http://java.sun.com/developer/onlineTraining/GUI/Swing1/shortcourse.html#JFCEditorPane>

    So, that's..
    <http://www.physci.org/api.jsp?class=javax.swing.JEditorPane>
    <http://www.physci.org/api.jsp?class=javax.swing.event.HyperlinkListener>
    You need to look at..

    HTH

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Apr 27, 2004
    #9
  10. Marte Brenne

    Roedy Green Guest

    On Tue, 27 Apr 2004 06:16:25 GMT, Andrew Thompson
    <> wrote or quoted :

    >[something screwy was happening with my feed
    >to usenet so that I received Roedy's response
    >to you before your post, so I only just saw
    >this bit..]


    This happens if one of the posters has a out of whack clock. Posts get
    tagged with the timestamp of the poster's clock, not of the newserver.
    I find this irritating since some people deliberately future stamp
    posts to make them stick at the top of the display. One goofball with
    an out of whack clock can confuse everyone.

    See http://mindprod.com/jgloss/atomiclock.html


    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Apr 27, 2004
    #10
  11. On Tue, 27 Apr 2004 08:17:17 GMT, Roedy Green wrote:

    > On Tue, 27 Apr 2004 06:16:25 GMT, Andrew Thompson
    > <> wrote or quoted :
    >
    >>[something screwy was happening with my feed
    >>to usenet so that I received Roedy's response
    >>to you before your post, so I only just saw
    >>this bit..]

    >
    > This happens if one of the posters has a out of whack clock.


    No, this was happening across multiple
    groups, my feed stopped for over 18 hours,
    then they began to trickle in, in bizarre
    order (and again across multiple groups,
    with no single connection but me).

    (ehh.. shrugs) It seems to be sorting itself out.

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Apr 27, 2004
    #11
  12. Marte Brenne

    Yan Lijun Guest

    in awt,the base "component" class support the "MouseListener",and it means
    nearly all components can receive mouse click events.

    for instance
    public class MouseClickListener extends MouseAdapter{
    public void mouseClick(MouseEvent evnet){
    ......
    }
    }

    Label label=new Label("text");
    label.addMouseListener(new MouseClickListener());

    so,when you click the label "text",method "mouseClick" will be invoked

    ÔÚ 23 Apr 2004 02:18:43 -0700 ʱ, (Marte Brenne) дÁË:
    --

    >Hi!
    >
    >Can anyone please tell me if it's possible to use hypertext in java? I
    >have designed a user interface, and I want something to happen when
    >you click on some Strings. Because it's a lot of text that I want to
    >make clickable, I can't use buttons.
    >
    >Thank you very much in advance!



    /**
    /* Java Is Not Platform-independent.It Is The Platform!
    */
     
    Yan Lijun, Apr 28, 2004
    #12
  13. Marte Brenne

    Marte Brenne Guest

    Thank you very much for all the answers I have received! And
    especially for the coding example :) If someone with the same problem
    is reading this, what I forgot to do was when setting text to the
    JEditorPane to include <A HREF> before and </A HREF> after the text to
    be clicked - like this:

    pane.setText("<A HREF>text to be clicked</A HREF>");

    Again - thank you very much for all your help!
     
    Marte Brenne, Apr 29, 2004
    #13
  14. On 29 Apr 2004 06:07:32 -0700, Marte Brenne wrote:

    > pane.setText("<A HREF>text to be clicked</A HREF>");


    pane.setText("<A HREF>text to be clicked</A>");

    Is actually slightly more valid, while..

    pane.setText("<A HREF='somebloodywhere.html'>text to be clicked<A>");

    Is even more so.. (shrugs) not sure about these
    closing '/' ---> </A> it looks like something
    from XML.. it is not needed for normal HTML..

    [ Waits for Chris S. to jump in and describe
    some arcane situation where it matters ;-) ]

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Apr 29, 2004
    #14
  15. Andrew Thompson wrote:

    > On 29 Apr 2004 06:07:32 -0700, Marte Brenne wrote:
    >
    >> pane.setText("<A HREF>text to be clicked</A HREF>");

    >
    > pane.setText("<A HREF>text to be clicked</A>");
    >
    > Is actually slightly more valid, while..
    >
    > pane.setText("<A HREF='somebloodywhere.html'>text to be clicked<A>");
    >
    > Is even more so.. (shrugs) not sure about these
    > closing '/' ---> </A> it looks like something
    > from XML.. it is not needed for normal HTML..
    >
    > [ Waits for Chris S. to jump in and describe
    > some arcane situation where it matters ;-) ]
    >


    AFAIK it was always supposed to be <A>...</A>, as with the <P>, the <B>, ...
    tags.

    Even in HTML you were supposed to close the tags properly, but
    unfortunately, a lot of HTML "programmers" got sloppy, and the browsers
    were always as liberal as possible in parsing the HTML on a page, so it
    didn't get noticed a lot.

    --
    Kind regards,
    Christophe Vanfleteren
     
    Christophe Vanfleteren, Apr 29, 2004
    #15
  16. On Thu, 29 Apr 2004 13:39:15 GMT, Christophe Vanfleteren wrote:
    > Andrew Thompson wrote:
    >> On 29 Apr 2004 06:07:32 -0700, Marte Brenne wrote:


    >> ...not sure about these
    >> closing '/' ---> </A> it looks like something
    >> from XML.. it is not needed for normal HTML..

    ....
    > AFAIK it was always supposed to be <A>...</A>, as with the <P>, the <B>, ...
    > tags.
    >
    > Even in HTML you were supposed to close the tags properly,


    (slaps forehead) I don't know _where_
    my head was at. But (ooOOuch!), I
    seem to have found it now..

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Apr 29, 2004
    #16
    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. Michael Kintner
    Replies:
    0
    Views:
    851
    Michael Kintner
    Nov 30, 2003
  2. Ilias Lazaridis
    Replies:
    0
    Views:
    578
    Ilias Lazaridis
    Feb 1, 2005
  3. DrTechMech
    Replies:
    0
    Views:
    420
    DrTechMech
    Sep 19, 2005
  4. manish sahu
    Replies:
    3
    Views:
    1,009
  5. Isaac
    Replies:
    0
    Views:
    378
    Isaac
    Jan 20, 2011
Loading...

Share This Page