Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Hypertext in java

Reply
Thread Tools

Hypertext in java

 
 
Marte Brenne
Guest
Posts: n/a
 
      04-23-2004
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!
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      04-23-2004
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
 
Reply With Quote
 
 
 
 
Pimousse
Guest
Posts: n/a
 
      04-23-2004
> 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


 
Reply With Quote
 
Marte Brenne
Guest
Posts: n/a
 
      04-26-2004
Andrew Thompson <(E-Mail Removed)> wrote in message news:<ufhaeqm50zci.rk4ohov2arig$(E-Mail Removed)>.. .
> 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.
 
Reply With Quote
 
Rogan Dawes
Guest
Posts: n/a
 
      04-26-2004
Marte Brenne wrote:

> Andrew Thompson <(E-Mail Removed)> wrote in message news:<ufhaeqm50zci.rk4ohov2arig$(E-Mail Removed)>.. .
>
>>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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      04-26-2004
On 26 Apr 2004 01:10:18 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (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.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      04-26-2004
On Mon, 26 Apr 2004 20:28:07 GMT, Roedy Green
<(E-Mail Removed)> 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.
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      04-26-2004
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
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      04-27-2004
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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      04-27-2004
On Tue, 27 Apr 2004 06:16:25 GMT, Andrew Thompson
<(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Free Hypertext Application Demo's and VB Scripting Information DrTechMech HTML 0 09-19-2005 02:35 AM
hypertext Ronald Murray Computer Information 2 10-22-2004 02:25 AM
ThunderBird 0.X and Hypertext link problem Jissma Firefox 1 09-16-2004 02:44 AM
On Google search, the sponsored links don't show company's name and I can't click on sponsored-link hypertext Bruce Computer Support 4 08-20-2004 04:06 AM



Advertisments