Web proxy server - Java Swing O Reilly } Of course, we
Java Swing O Reilly } Of course, we also need to register the listener for these events in our init() method: tree.addTreeExpansionListener(this); 17.7 Rendering and Editing As with the table cells covered in previous chapters, you can create your own tree cell renderers and editors. The default renderers and editors usually do the trick, but you’re probably reading this because they don’t do the trick for you, so forge onward! If you went through building your own renderers and editors for tables, you’ll find this material quite familiar. The tree uses renderers and editors in much the same way that tables do. 17.7.1 Rendering Nodes Why would I want to render a node? Good question. One reason is that you want to modify the look-and-feel of a tree without writing a whole UI package for trees. If you had some special way of presenting the “selected” look, for example, you could write your own tree renderer, and still use the default look-and-feel stuff for all of your other components. You might want to render something other than a string with an icon for the nodes of your tree. Or, as we mentioned above, you might want tooltips that vary based on the particular node you rest your cursor on. As always, “because I can” is also a good reason. 17.7.1.1 But I only want to change the icons! Before we tackle creating our own renderers, we should point out that the Metal look-and-feel lets you modify the set of icons used by a tree for the leaves and folders. To change the icons, you use the UIManager class and the look-and-feel icons for trees. You can also use the client property JTree.lineStyle to affect the type of lines drawn from folders to leaves. Chapter 26, has much more detail on look-and-feels, but this short example should get you started for the tree-specific properties. You call the putClientProperty() method on your instance of the tree to set its line style. Your choices for styles are: Horizontal Thin horizontal lines drawn above each top-level entry in the tree (the default) Angled The Windows-style right-angle lines from a folder to each of its leaves None No lines at all You call the UIManager.put() method to modify the icons used by all trees. The icons you can replace are: - 517 -
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.