Thursday November 20, 2008
Getting Started with the Print API
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.
Nov 20 2008, 07:43:30 AM PST Permalink


