Geertjan's Blog

  • June 7, 2006

Showing a Module's HTML File in the IDE's Browser

Geertjan Wielenga
Product Manager
Maybe you have an HTML file in your NetBeans module and you want to display it to the user. For example, here's an HTML file that could be displayed (instead of the current readme.txt) for the GUIFormExamples project sample, giving the user some basic information:

Read on if you have a similar use case. First, create a module project and a window component, by using the appropriate wizards. One of the files that you'll get generated for you is a TopComponent. Then drop a JEditorPane onto the TopComponent. Name it MainTextArea. Finally, extend the Constructor for the TopComponent, assuming you've called it WelcomePageTopComponent (the highlighted part is all I added):

private WelcomePageTopComponent() {
setName(NbBundle.getMessage(WelcomePageTopComponent.class, "CTL_WelcomePageTopComponent"));
setToolTipText(NbBundle.getMessage(WelcomePageTopComponent.class, "HINT_WelcomePageTopComponent"));MainTextArea.setEditorKit(new HTMLEditorKit());
try {
String s = NbBundle.getMessage(WelcomePageTopComponent.class, "WelcomeDocument");
URL demoDetailsURL = new URL(s);
} catch (IOException ex) {


Notice that there's a reference to a Bundle.properties file. That's where you set the location of the HTML page as a key-value pair:


And that's all you need to do. Now the HTML file will be displayed in the IDE's Swing browser when the related menu item (also generated by the window component wizard) is invoked.

Join the discussion

Comments ( 3 )
  • Thiago HP Wednesday, June 7, 2006

    Hi Geertjan!

    Would it be possible to include an external CSS file?

    Meanwhile, I tried to get the syntax highlighting color and font information from the JEditorPane through its StyledDocument but all it gave me was one Element without any formatting info for each line of the source code. :(

  • Geertjan Thursday, June 8, 2006
    Hi Thiago, not sure. I'll experiment with the CSS idea. Sounds interesting. And, I think, instead of StyledSocument, look at the section "Associating the EditorKit with a JEditorPane", which is right at the end of http://platform.netbeans.org/tutorials/nbm-mfsyntax.html.
  • Geertjan Thursday, June 8, 2006
    duh. I just realized...here the HTML file isn't displayed in a browser at all, but in a JEditorPane within my own TopComponent.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.