This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.
|
java911@microsoft.com Download the code (9KB) |
The form's constructor begins by creating a TreeView control through a call to the TreeView class's no-arg constructor. The decision to make TreeView's constructor take no arguments is consistent with the design of WFC. In general, WFC controls are constructed with no arguments; individual properties are set by calling get/set methods on the created object. This two-phase construction of objects makes things more consistent and significantly simpler for higher-level entities like builder tools. After constructing the TreeView object, the form's constructor then wires up an event handler for onResize events by calling addOnResize. The event handler, onResize, simply resizes the TreeView control to fill the full client area of the form, as returned by getClientSize. Next, a hierarchy of seven nodes is created and assigned to the TreeView control by calling TreeView.addNode. Each TreeNode object in the hierarchy can have zero or more TreeNode children. The children of individual TreeNodes are added by calling TreeNode.addNode. Once the TreeView has been populated with TreeNode objects, it is added to the form. The form is then shown as a dialog with an appropriate title. The neat thing about just using the existing Win32 APIs as exposed by WFC in Java is how much you get for so little effort. This does cut both ways, though. As you have seen, creating a TreeView control containing text nodes is quite easy (and you can even annotate the text nodes with graphic images in fairly short order). But the underlying Win32 TreeView control is somewhat limited. Most importantly, it is not possible to put arbitrary components (like a checkbox, for example) into a TreeView. You will, generally speaking, find the same to be true across the board with WFC; the Win32 functionality is exposed, wrapped, and often simplified, but it is not particularly enhanced. For those of you who are well initiated in the intricacies of Win32, this will not be much of a problem. But if you are a novice and are trying to do something that the Win32 platform doesn't inherently support, you may run into some difficult issues here and there.
How hard is it to display a static bitmap image in WFC?
What happens if the bitmap file doesn't exist? The system will throw an Error like this: |
|
Because the error is not a checked exception, it is not necessary to write code to handle the case where the exception is thrown. Handling the error is strictly optional. I like this design decision because it doesn't force unwanted handling of a condition that may not be a concern in many applications, and yet you can still catch the error if you need to.
Can I create tooltips in WFC?
How do I create menus in WFC?
How can I create toolbars in WFC?
How can I get a list of available fonts using WFC?
|
|
From the August 1998 issue of Microsoft Interactive Developer.