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

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 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.


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. :(

Posted by Thiago HP on June 07, 2006 at 01:56 AM PDT #

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

Posted by Geertjan on June 08, 2006 at 01:34 AM PDT #

duh. I just the HTML file isn't displayed in a browser at all, but in a JEditorPane within my own TopComponent.

Posted by Geertjan on June 08, 2006 at 06:48 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« November 2015