Archive for August, 2007

Make my own web site - Java Swing O Reilly These methods register and

Friday, August 31st, 2007

Java Swing O Reilly These methods register and unregister listeners interested in finding out that the editor has a new value for the cell. One such listener would be the tree currently under edit. 17.7.7.3 Fields protected Color borderSelectionColor Stores the value for the borderSelectionColor property. protected boolean canEdit Stores the value used by the isCellEditable() method. It gets its value during the getTreeCellEditorComponent() call based on the values passed in. protected transient Component editingComponent protected Container editingContainer These fields store the component that will perform the editing and its container, respectively. protected transient Icon editingIcon Stores the Icon to use when editing a cell. This is not a means to allow a different icon to show up during editing. In the current implementation, it merely serves to reflect the correct icon already associated with the cell in the tree and make that icon available for the rest of the class. (In other words, if you start editing a cell with an open folder icon, the text field will have an open folder icon to its left when it pops up.) protected Font font Stores the value for the font property. A null value indicates the font from the renderer should be used. protected transient TreePath lastPath Stores the last path that was selected in the tree. protected transient int lastRow Set during the getTreeCellEditorComponent() call, it contains the row of the cell that should be edited. protected transient int offset Contains the x position (offset for the current cell) for placing the editing component or for calculating what constitutes the “interesting” part of the cell. In this context, interesting means “without the tree’s icon.” protected TreeCellEditor realEditor The editor that handles the editing. The various CellEditor methods implemented for this class delegate to this object. - 525 -
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Fedora web server - Java Swing O Reilly 17.7.6 The TreeCellEditor Interface

Friday, August 31st, 2007

Java Swing O Reilly 17.7.6 The TreeCellEditor Interface Like the TreeCellRenderer interface, the TreeCellEditor interface has one method: public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row) Allows you to configure the editor just before it pops up on the screen. In our example, we use this method to select the current operator in the combo box or to set the current text value for the text field. In addition to this method, you also need to keep track of things like whether or not you can even edit this tree node. Most of that information will come from the CellEditor interface (which TreeCellEditor extends). 17.7.7 The DefaultTreeCellEditor Class The JDK1.2 beta4 release gives us another useful addition to the tree package: the DefaultTreeCellEditor class. This class can be used to supply an editor for your tree cells that lets icons associated with the cells remain. (That was a problem in previous releases.) You can use a default text field to edit cells, or you can wrap your own custom editor in this class to make use of the start-up and rendering features. The DefaultTreeCellEditor class will start editing a cell after a triple-click of the mouse, or after a “click-pause-click wait for 1200 milliseconds” sequence. 17.7.7.1 Properties The DefaultTreeCellEditor properties are shown below in Table 17.16: Table 17.16, DefaultTreeCellEditor Properties Property Data Type get is set bound Default Value borderSelectionColor Color from L&F cellEditorValue* Object font* Font from L&F tree[7] JTree from constructor [7] This property has a protected set() method. The font and borderSelectionColor properties determine the visible qualities of the editor. The cellEditorValue property comes from the CellEditor interface discussed in detail in Chapter 27. (It just contains the current value stored in the editor.) The tree property is the JTree whose cell is being edited. 17.7.7.2 Events As dictated by the CellEditor interface, the DefaultTreeCellEditor class generates ChangeEvent objects for cell editor events. The usual add and remove methods are present: public void addCellEditorListener() public void removeCellEditorListener() - 524 -
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

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

Thursday, August 30th, 2007

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.

Java Swing O Reilly want to return a (Web server setup)

Thursday, August 30th, 2007

Java Swing O Reilly want to return a subclass of JComponent. If you want multiple components to do your rendering (or your editing, for that matter), extending Container is a good place to start. This interface defines one method: public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) This method takes as arguments all of the information relevant to rendering a tree node. You are free to ignore any argument that doesn’t interest you, or you can go directly to the tree node, value. You can then create and return a component that will draw your node correctly. A simple way to build your first renderer is to extend the JLabel class. You’ll probably want to keep some other state information around, as well. Here’s the code that built the expression renderer above. In the constructor, we create a center-aligned label with a medium-sized monospaced font. When the program renders a cell or displays a cell’s tooltip (by calling getTreeCellRendererComponent()) we set the current color for the foreground and background according to the selected status of our object. We could also query our object for other bits of information if needed. To get the (slightly) more interesting tooltips working, we override the getToolTipText() method to return a different string, depending on whether the mouse is over is a node or a leaf. We use the opaque property to determine whether we see the blue background. // ExpressionTreeCellRenderer.java // A renderer for our expression cells. // import java.awt.*; import javax.swing.*; import javax.swing.tree.*; public class ExpressionTreeCellRenderer extends JLabel implements TreeCellRenderer { Color backColor; boolean isLeaf; public ExpressionTreeCellRenderer() { // Pick a nice, big, fixed width font for our labels setFont(new Font(”Monospaced”, Font.PLAIN, 16)); setHorizontalAlignment(SwingConstants.CENTER); } public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { - 522 -
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Java Swing O Reilly protected Color borderSelectionColor protected (Jetty web server)

Wednesday, August 29th, 2007

Java Swing O Reilly protected Color borderSelectionColor protected transient Icon closedIcon protected transient Icon leafIcon protected transient Icon openIcon protected Color textNonSelectionColor protected Color textSelectionColor These fields store the values for their respective properties. protected boolean selected This field tracks whether or not the cell is currently selected. 17.7.2.4 Rendering Methods Beyond simple property accessors and mutators, you will find two other methods in this class that help display the cell the way you would expect. public void paint(Graphics g) This overridden method paints the background for a cell based on its selected status. public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) This method comes from the TreeCellRenderer interface. It returns the actual Component that will be used to display the cell. The various parameters to the method configure the cell renderer and are discussed in more detail later. 17.7.3 Custom Renderers Now let’s look at writing our own renderer. Our expression tree uses the default folder and leaf icons, which are more appropriate to files and filesystems. We can write a more formal renderer that uses a nice big monospaced font and does away with the little folder icons on the operators. Figure 17.12 shows the results. Figure 17.12. Expression tree with a custom renderer 17.7.4 The TreeCellRenderer Interface With this interface and your favorite Component subclass, you can render a tree cell any way you like, regardless of the look-and-feel in place. While you can return any component as a renderer, because of the problems with mixing heavyweight and lightweight components, you’ll probably - 521 -
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Jetty web server - Java Swing O Reilly } 17.7.2 The DefaultTreeCellRenderer

Tuesday, August 28th, 2007

Java Swing O Reilly } 17.7.2 The DefaultTreeCellRenderer Class The JDK1.2 beta4 release introduced another alternative to the look-and-feel setup for trees. In addition to setting up icons and line styles as we do in the previous example, you can use the DefaultTreeCellRenderer class and its properties to customize tree display. DefaultTreeCellRenderer is an extension of the JLabel class that implements the TreeCellRenderer interface (discussed later), and is devoted to making your tree appear on screen the way you want it to look. 17.7.2.1 Properties Table 17.15 shows the properties associated with this new class: Table 17.15, DefaultTreeCellRenderer Properties Property Data Type get is set bound Default Value background*[5] Color From L&F backgroundNonSelectionColor Color From L&F backgroundSelectionColor Color From L&F borderSelectionColor Color From L&F closedIcon Icon From L&F defaultClosedIcon Icon From L&F defaultLeafIcon Icon From L&F defaultOpenIcon Icon From L&F font*[5] Font From L&F leafIcon Icon From L&F openIcon Icon From L&F preferredSize*[6] Dimension From L&F textNonSelectionColor Color From L&F textSelectionColor Color From L&F [5] This property has an overridden set() method that does not allow UIResource objects (such as ColorUIResource and FontUIResource) as its argument. [6] This property overrides the get() method to increase the width of the preferred size by 3 pixels. The various properties let you configure the icons to use for leaves, open folders and closed folders. You can also control the colors used for the text and selected cells. 17.7.2.2 Constructors The DefaultTreeCellRenderer class has only one constructor: public DefaultTreeCellRenderer() This constructor simply returns a new instance of the class. 17.7.2.3 Fields protected Color backgroundNonSelectionColor protected Color backgroundSelectionColor - 520 -
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Web hosting e commerce - Java Swing O Reilly // TestTree3.java // A

Tuesday, August 28th, 2007

Java Swing O Reilly // TestTree3.java // A Simple test to see how we can build a tree and customize its icons. // import java.awt.*; import java.util.*; import java.awt.event.*; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.tree.*; public class TestTree3 extends JFrame { JTree tree; DefaultTreeModel treeModel; public TestTree3() { super(”Tree Test Example”); setSize(200, 150); addWindowListener(new BasicWindowMonitor()); // Add in our own customized tree iconsUIManager.put(”Tree.leafIcon”, new ImageIcon(”world.gif”)); UIManager.put(”Tree.openIcon”, new ImageIcon(”door.open.gif”)); UIManager.put(”Tree.closedIcon”, new ImageIcon(”door.closed.gif”)); UIManager.put(”Tree.expandedIcon”, new ImageIcon(”unlocked.gif”)); UIManager.put(”Tree.collapsedIcon”, new ImageIcon(”locked.gif”)); } public void init() { // Build the hierarchy of containers & objectsString[] schoolyard = {”School”, “Playground”, “Parking Lot”, “Field”}; String[] mainstreet = {”Grocery”, “Shoe Shop”, “Five & Dime”, “Post Office”}; String[] highway = {”Gas Station”, “Convenience Store”}; String[] housing = {”Victorian_blue”, “Faux Colonial”, “Victorian_white”}; String[] housing2 = {”Mission”, “Ranch”, “Condo”}; Hashtable homeHash = new Hashtable(); homeHash.put(”Residential 1″, housing); homeHash.put(”Residential 2″, housing2); Hashtable cityHash = new Hashtable(); cityHash.put(”School grounds”, schoolyard); cityHash.put(”Downtown”, mainstreet); cityHash.put(”Highway”, highway); cityHash.put(”Housing”, homeHash); Hashtable worldHash = new Hashtable(); worldHash.put(”My First VRML World”, cityHash); // Build our tree out of our big hashtable tree = new JTree(worldHash); // Pick an angled line style tree.putClientProperty(”JTree.lineStyle”, “Angled”); getContentPane().add(tree, BorderLayout.CENTER); } public static void main(String args[]) { TestTree3 tt = new TestTree3(); tt.init(); tt.setVisible(true); } - 519 -
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Java Swing O Reilly Tree.openIcon Used for opened (Web hosting reseller)

Monday, August 27th, 2007

Java Swing O Reilly Tree.openIcon Used for opened folders Tree.closedIcon Used for closed folders Tree.leafIcon Used for leaves Tree.expandedIcon Used for the one-touch expander when its node is expanded Tree.collapsedIcon Used for the one-touch expander when its node is collapsed Thus, if t is a JTree, and icon is some kind of Icon, the code: t.putClientProperty (”JTree.lineStyle”, “Angled”); UIManager.put (”Tree.openIcon”, icon); sets the tree’s line style to Angled, and sets the icon for opened folders to icon. Figure 17.11 shows a tree with custom icons and angled lines connecting the nodes. (This is also a sample of a JTree used for some hierarchical data other than a filesystem. Here we have a VRML world builder with the containers representing composite scenes and the leaves representing atomic objects in the world.) Figure 17.11. A sample JTree with custom icons and line style And here’s the code that installed these customizations. The customizations happen in two places. The various icons used throughout the tree are installed in our constructor and apply to any tree instance we create. The lineStyle property is something we associated with the particular instance of JTree in our init() method. Again, this property only has an effect when you are using the Metal look-and-feel. - 518 -
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Web proxy server - Java Swing O Reilly } Of course, we

Monday, August 27th, 2007

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.

Web server - Java Swing O Reilly Similar to other exception

Sunday, August 26th, 2007

Java Swing O Reilly Similar to other exception classes, these constructors build new exceptions with the proposed expansion event, and an optional message. 17.6.7.4 Fields protected TreeExpansionEvent event While the ExpandVetoException class does not provide any public read access to the event used in constructing the exception, that event is stored in this protected field for use by subclasses. 17.6.8 Implementing the Expansion Listener Interface If you look back at our expression tree, you’ll notice that the nodes are never told that they have been expanded or collapsed. That has the side effect of leaving the entire expression represented below a given operator as the displayed string. Without listening to any of these events, a completely expanded expression tree might look like Figure 17.9. We would like an expanded branch to show only the operator associated with that branch, as in Figure 17.9. Figure 17.9. Expression tree with static labels for the operator nodes 17.10. Expression tree with “dynamic” operator labels updated by expansion events We can accomplish that by implementing the TreeExpansionListener interface and adding the following bits of code to the ExprTree class. public void treeExpanded(TreeExpansionEvent tee) { OpNode node = (OpNode)te.getPath().getLastPathComponent(); node.setExpanded(true); treeModel.refresh(tee); } public void treeCollapsed(TreeExpansionEvent tee) { OpNode node = (OpNode)te.getPath().getLastPathComponent(); node.setExpanded(false); treeModel.refresh(tee); - 516 -
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.