File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to turn a chat message in an Textarea to a proper line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to turn a chat message in an Textarea to a proper line" Watch "How to turn a chat message in an Textarea to a proper line" New topic
Author

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

Sege Stephen
Ranch Hand

Joined: Oct 06, 2007
Posts: 51
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

Joined: Oct 27, 2005
Posts: 19682
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sege Stephen
Ranch Hand

Joined: Oct 06, 2007
Posts: 51
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

Joined: Oct 06, 2007
Posts: 51
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Oct 27, 2005
Posts: 19682
    
  20

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

Joined: Oct 06, 2007
Posts: 51
Ok thank you Guys, I will change it to EditorPane. Hopefully it would be easy to code.
Sege Stephen
Ranch Hand

Joined: Oct 06, 2007
Posts: 51
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

Joined: Jun 13, 2009
Posts: 2180
    
    7
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

Joined: Oct 06, 2007
Posts: 51
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to turn a chat message in an Textarea to a proper line