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() {
    initComponents();
    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);
        MainTextArea.setPage(demoDetailsURL);
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

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:

WelcomeDocument=nbresloc:/org/netbeans/modules/welcomepage/welcome.html

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.

Comments:

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 http://platform.netbeans.org/tutorials/nbm-mfsyntax.html.

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

duh. I just realized...here 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
About

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.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today