File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Swing / AWT / SWT
Author
Link to open using JEditor Pane
VenuArchana Aradhyula
Greenhorn
Joined: Sep 02, 2008
Posts: 13
posted
Nov 03, 2008 23:30:00
0
I have a label with the name
www.google.com.
When i click on this link the website has to be opened. For this i have written mouse events and i also used JEditor pane.
JLabel lblSite = new JLabel(); lblSite.setText(strWeb); lblSite.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { try { URL url = new URL("http://www.xyratex.com"); JEditorPane editorPane = new JEditorPane(url); editorPane.setEditable(false); editorPane.addHyperlinkListener(new XHyperlinkListener()); editorPane.setContentType("text/html"); editorPane.setPage(url); } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } public void mouseEntered(MouseEvent e) { lblSite.setCursor(new Cursor(Cursor.HAND_CURSOR)); } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); class XHyperlinkListener implements HyperlinkListener { public void hyperlinkUpdate(HyperlinkEvent evt) { if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane pane = (JEditorPane)evt.getSource(); try { // Show the new page in the editor pane. pane.setPage(evt.getURL()); } catch (IOException e) { } } } }
Please check the above code.
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8562
I like...
posted
Nov 03, 2008 23:58:00
0
Umm..What exactly is your question?
[
Donate a pint, save a life!
] [
How to ask questions
] [
Onff-turn it on!
]
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4201
3
I like...
posted
Nov 04, 2008 00:25:00
0
Just another cross poster.
http://forums.sun.com/thread.jspa?threadID=5344840
luck, db
There are no new questions, but there may be new answers.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35437
9
posted
Nov 04, 2008 00:29:00
0
Please
BeForthrightWhenCrossPostingToOtherSites
. It's the polite thing to do.
Android apps
–
ImageJ plugins
–
Java web charts
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Link to open using JEditor Pane
Similar Threads
opening link in new window
JEditorPane problem
retrieving string from a webpage
Open Web pages inside JavaFX
JLabel pan image
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter