Java Swing O Reilly if (selected) { setOpaque(true); (Web and email hosting)

Java Swing O Reilly if (selected) { setOpaque(true); setForeground(Color.white); } else { setOpaque(false); setForeground(Color.black); } setText(value.toString()); isLeaf = leaf; return this; } // Override the default to send back different strings for folders and leaves public String getToolTipText() { if (isLeaf) { return “Leaf”; } return “Node”; } // Override the default to give us a bit of horizontal padding public Dimension getPreferredSize() { Dimension dim = super.getPreferredSize(); if(dim != null) { dim = new Dimension(dim.width + 4, dim.height); } return dim; } } And here’s the line in ExprTree.java that tells our tree to use our renderer instead of the default one: tree.setCellRenderer(new ExpressionTreeCellRenderer()); If you want the tooltips to be active, you have to register the tree with the ToolTipManger(discussed earlier in this chapter). 17.7.5 Editing Nodes One of the other things you may want to do with a tree node is edit it. Each look-and-feel shipped with Swing implement’s basic text field editors for tree nodes, but it is possible to use other components to edit nodes. In fact, since editors are just subclasses of Component, you can even build your own editor. For example, we can create an expression editor like you see in Figure 17.13 that picks one of two possible components. If you want to edit an operator, you’ll get a JComboBox with the four various supported operators in the list. If you want to edit an integer, you’ll get a JTextField. Figure 17.13. Expression tree with a custom editor for the operator nodes - 523 -
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Leave a Reply