Geertjan's Blog

  • November 20, 2008

Getting Started with the Print API

Geertjan Wielenga
Product Manager
The next newly official API in 6.5 is the Print API. It works in the same way as the new 'feature' that lets you specify the size of the popped-out TopComponent: via a client property (which implies that there should be the same ui for it, i.e., a checkbox in the Window Component wizard):
putClientProperty("print.printable", Boolean.TRUE); // NOI18N

Just put the above in your TopComponent constructor and you're good to go. Let's say, for example, that this is what your TopComponent looks like...

Now, to provide Print functionality, all you need to do is add the above single line of code to the constructor of the above TopComponent. Then the File | Print menu item will automatically be enabled. Alternatively, instead of clicking that menu item, press Ctrl-Alt-Shift-P. (According to Tom Wheeler in an e-mail to me, in order to do this "you'd need amazing dexterity, several years of emacs experience or assistance from a passerby to press all those keys simultaneously".)

You'll then find yourself with this dialog, which you can use for printing purposes:

That's pretty cool. One step in the direction of providing business functionality out of the box. I'm looking forward to similar enablement-functionality for login, persistence, and other business/CRUD functionality, as described here in Issuezilla (which should get you here at some point). After all, as someone said at the NetBeans Demo Camp in Munich: "Why does JSR-296 have a cool business application generator in NetBeans IDE, while the NetBeans Platform doesn't?" Good question! The concept of a NetBeans Business Platform (something that Ralph Lance, at the same demo camp in Munich, asked me about... 3 years ago or so... and I was reminded of the moment I saw him again) would be great to introduce. It would be an absolutely killer approach to all the low level NetBeans Platform details.

Join the discussion

Comments ( 2 )
  • Jacek Thursday, November 20, 2008

    Very nice. But I think NB Platform would have a lot more uptake if it wasn't so NB-specific...I think if you rewrote it to run on top of an OSGi container using regular OSGi plugins and extension points a lot more people would be open to it.

    Like it or not but OSGi is the defacto standard for module/plugin development on the Java platform.

  • Geertjan Thursday, November 20, 2008

    Jacek, you'd be surprised to find how many people within Sun agree with you. Look at GlassFish, for example. And here's something that should interest you:


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.