Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to turn a chat message in an Textarea to a proper line

 
Sege Stephen
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eg, you send a message "My website is www.magaphone.com" in a textarea

I want it to appear as active link. Any help would be appreciated
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps a non-editable JEditorPane is better. That allows you to attach hyperlink listeners. All you need to do is make sure the contents are in HTML format.
 
Sege Stephen
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I have seen that . Will now give it more thought.

p.s I was partly asleep when I created this post, wow, so many typos. Will fix it
 
Sege Stephen
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Perhaps a non-editable JEditorPane is better. That allows you to attach hyperlink listeners. All you need to do is make sure the contents are in HTML format.


Hi, I cannot use that JEditorPane as thisl textArea is already defined. It takes text Strings most of the time, the only time you would need it to show a URL is when some one enters www. something.com and click send. Other than that, all the other functions are ok in it.

I need to know how to handle that.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As already suggested, you handle it by not using a Textarea.

What do you mean it's "already defined"? What stops you from changing that and using the right component instead?
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It may be possible with JTextArea, but it will be quite hard. First, you will need a Highlighter that underlines, to highlight the "links". Next, you need a mouse (motion) listener that a) changes the cursor when the cursor is over such a "link" and back when the cursor leaves one, and can detect a link when you click on it.

It's not something I would like to do myself, frankly.
 
Sege Stephen
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thank you Guys, I will change it to EditorPane. Hopefully it would be easy to code.
 
Sege Stephen
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to launch a browser from the GUI

Hello, I am now using JEditor pane, I can now read a link from the text message and open it. I have a simple problem. It i launches in the gui, i would like it to open the link in an external web broswer


I thought calling toExternalForm() will do the magic, but it doesn't, i have searched on the net but can't find something. Please point me in the right direction.

Sorry if I'm always appearing to be asking simple question, I am still learning.
 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sege Stephen wrote:How to launch a browser from the GUI

It i launches in the gui, i would like it to open the link in an external web broswer


Use the Desktop class which what added to the API in JDK6.
 
Sege Stephen
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:
Sege Stephen wrote:How to launch a browser from the GUI

It i launches in the gui, i would like it to open the link in an external web broswer


Use the Desktop class which what added to the API in JDK6.



Sir, you made my day. Much appreciated. I can now go out and relax.

Just for anyone who maybe looking for the same solution

here
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic