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 Open a Web Page inside a jDesktopPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Open a Web Page inside a jDesktopPane" Watch "Open a Web Page inside a jDesktopPane" New topic
Author

Open a Web Page inside a jDesktopPane

Olivier López
Ranch Hand

Joined: Jan 31, 2010
Posts: 32
Hi everybody, im a new java programmer and in the university I am, I have to learn about the new caracteristics of java6 for the "Sun Certified Java Programmer (SCJP)" exam...

I want to make a java aplication that opens a web site inside a JDesktopPane, or another similar container like jPanel, or jEditorPane but it´s being a little difficult xD.

With this code i already opened a URL in the internet explorer:

public void inicia(){
try {
String url = jTextField1.getText();
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)) {
}
desktop.browse(new URI(url));
} catch (IOException ex) {
Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
} catch (URISyntaxException ex) {
Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
}

}

This is what i have, but its not what i want... i want something like:

jDesktopPane1(url);

But i dont know how to show the website inside the jDesktopPane...

I had already read the post of this guy: http://www.coderanch.com/t/462717/Java-FX/java/Open-Web-pages-inside-JavaFX

but im not using java FX, im using java SE with netbeans...


I want something like this, just... "open a website"
https://jdic.dev.java.net/documentation/incubator/JDICplus/ws/TabbedBrowser.jnlp




Can someone give me a light please??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19781
    
  20

A non-editable JEditorPane should work:
You can also listen for clicks on links using a HyperLinkListener:
Keep in mind that JEditorPane does not really support anything past HTML 3.2. I believe SwingX has a component with better HTML support.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Olivier López
Ranch Hand

Joined: Jan 31, 2010
Posts: 32
AWESOME¡¡¡¡¡¡

THANKS a LOOOOOT¡¡¡¡¡

It really works¡¡¡¡

I never expected a so fast and accurate answer...

Again... thanks a lot


By The Way... I have a doubt... The jEditorPane shows the website, but i cannot interact with it... i mean, if i open google and write something in the search bar, it doesnt make anything... the hyperlink listener you wrote is for that?

I changed the code like this:



But is not working, when i clic on a link in the displayed website, it doesnt make anything

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19781
    
  20

As far as I know, forms (which are used by Google and many, many other sites) are not supported by JEditorPane, only regular links.
Olivier López
Ranch Hand

Joined: Jan 31, 2010
Posts: 32
xXxOlivierxXx Elric wrote: But is not working, when i clic on a link in the displayed website, it doesnt make anything



Yea xD, google was just an example, any hyperlink of any website works

It's my hyperlink listener code ok?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Open a Web Page inside a jDesktopPane