Archive for July, 2007

Java Swing O Reilly If a container has (Web hosting contract)

Tuesday, July 31st, 2007

Java Swing O Reilly If a container has a focus cycle of its own, it should override the JComponent method isFocusCycleRoot() and return true. If the method returns true, then the container is known as the root container of the focus cycle. The root container is allowed to indicate whether or not it is managing focus . If it is, it should override the isManagingFocus() method and return true. When a container is managing focus, the focus manager is disabled and all key events are sent to the container for processing. By default, the isManagingFocus() method returns false, allowing the Swing focus manager to handle the task of shifting and traversing the focus. With any JComponent, you can explicitly name the component that should receive the focus next by setting the nextFocusableComponent property. In addition, focus can be programmatically requested through the JComponent method requestFocus() , which the focus manager can call to shift the focus to this component. This is often done when the user selects the object (i.e., presses a JButton). If you don’t want your component to be able to respond to requestFocus() calls, you can set the requestFocusEnabled property of JComponent to false. There is an important distinction here: setting the requestFocusEnabled property to false does not mean that the focus cannot be traversed onto your component; it simply means that it cannot be programmatically requested. JComponent provides a similar property, focusTraversable, that you can enable or disable to specify whether a component receives the focus when traversed. Note the difference between the two. If you wanted to allow a JButton to gain the focus when clicked, but skipped in the focus cycle, you would set the requestFocusEnabled property to true and the focusTraversable property to false. If you wanted to prevent focus from being shifted to the JButton when clicked, you would set the requestFocusEnabled property to false. If you wanted the JButton to ignore focus traversal and focus requests (i.e., never have the focus), you would set both properties to false. We discuss the concept of focus and the FocusManager in detail in Chapter 28. 3.3.2.12 Keyboard Events Swing components can be programmed to trigger various actions when certain keystrokes occur. For example, Swing components automatically handle focus-related keyboard events. The default focus manager searches only for TAB and SHIFT-TAB keystrokes, altering the focus and consuming the keystrokes when detected. If the focus manager does not know how to handle a keystroke, it checks to see whether the processComponentKeyEvent() method can consume it. This method currently does nothing. However, you can override it in a subclass if you want to react to a keystroke in your own way. If neither of these succeeds in consuming the key event, the JComponent class checks to see if a keyboard action has been registered for that keystroke. A keyboard action binds a Swing action and a keystroke to a specific component. - 66 -
We recommend high quality webhost to host and run your jsp application: christian web host services.

Java Swing (1 on 1 web hosting) O Reilly If you wish to

Tuesday, July 31st, 2007

Java Swing O Reilly If you wish to activate debugging for the component’s graphics, you can pass one or more debugging flags into the setDebugGraphicsOptions() method of JComponent. The debugging flags are given in Table 3.6. Table 3.6, Constants for Debug Graphics Options DebugGraphics Constant Description Causes each graphics primitive to flash a user-configurable number of DebugGraphics.FLASH_OPTION times as it is being rendered. DebugGraphics.LOG_OPTION Prints a text message to the screen as each graphics primitive is drawn. Raises a window that shows the drawing that is taking place in the DebugGraphics.BUFFERED_OPTION offscreen buffer. This is useful in the event that the double-buffered feature has been activated. DebugGraphics.NONE_OPTION Disables all debug graphics options. The debug options outlined in Table 3.6 are bits in a binary mask; you can set more than one at the same time by using the bitwise OR ( | ) operator, as shown here: JButton myButton = new JButton(”Hello”); // JButton extends JComponentmyButton.setDebugGraphicsOptions(DebugGraphics.FLASH_OPTION | DebugGraphics.LOG_OPTION); When any of the debug graphics options are set, the getComponentGraphics() method of JComponent returns a DebugGraphics object, instead of a normal Graphics object. As we mentioned above, this is the same type of object that is passed to the UI delegate of the component. When a component draws itself, it calls upon the functionality of the DebugGraphics object to perform the task, just as it would with a typical Graphics object. The drawing primitives are then slowed or logged so that the user can help identify any problems. 3.3.2.11 Focus and Focus Cycle The term focus refers to the active component on the screen. We typically think of the active component as the frame or window that is the current recipient of mouse and keyboard events. Other components, such as buttons and text fields, can have the focus as well. Visual cues, like a colored title bar or a dashed outline, often help us determine where the current focus resides. When we click on another component with the mouse, the focus is typically shifted, and that component is now responsible for consuming mouse and keyboard events. You can also traverse the focus by pressing the TAB key to move forward or the TAB and the SHIFT key together to move backward. This causes the focus to cycle from one component to the next, eventually completing a loop and returning to its original position. This loop is called the focus cycle . A group of components within a single container can define a focus cycle of its own. If the container has its own focus cycle, the focus repeatedly traverses through all of its children that accept the focus. The focus cycle is typically determined by the location of components in the container, although you can create your own focus manager if you require a different behavior. With the default focus manager, the component closest to the top-left corner of the container always receives the focus first. The focus then moves from left to right across the components, and from top to bottom. Figure 3.9 shows how the default focus cycle shifts focus between components in a container. Figure 3.9. The default container focus cycle - 65 -
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

Java Swing O Reilly With double buffering, transparency (Domain and web hosting)

Monday, July 30th, 2007

Java Swing O Reilly With double buffering, transparency is maintained in non-opaque components because the graphics underneath the component are copied into the buffer first before any off-screen rendering takes place. However, there is a slight penalty for double buffering non-opaque components, because Swing is performing two area copies instead of one: one to copy the background over, and one to copy the background plus the component back. Buffers also chew up a great deal of memory. Therefore, the repaint manager tries to avoid initializing and using more than one off-screen buffer at a time. For example, if an off-screen buffer has been set for both a container and one of its children, the buffer for the parent container is used for both components. 3.3.2.9 Serialization Objects that extend JComponent are serializable; that is, the object’s data at that point can be written out, or serialized, and written onto an output stream, which might send it over a network or save it in a file.[4] The serialized output can later be deserialized back into memory, where the object will continue to operate from its original state. Object serialization gives Java programmers a powerful and convenient way to store and retrieve object data, as opposed to saving or transmitting state data in custom-made storage files. Serialization also provides the ability to transfer quickly active components from one virtual machine to another, which can be useful in remote method invocation (RMI) and other forms of distributed computing. [4] The only exceptions to this are fields marked with the transient keyword. You can serialize components in Swing as you normally would in Java: by passing a reference to the object into the writeObject() method of an ObjectOutputStream object. In the event that the serialized object contains a reference to another object, the serialization algorithm recursively calls writeObject() on that object as well, continuing until all objects in the class hierarchy are serialized. The resulting object graph is then written out to the output stream. Conversely, you can deserialize a component back in by using the readObject() method of an ObjectInputStream , which reverses the entire process. The baseline for serialization is JDK 1.2. If you serialized objects with JDK 1.1/Swing 1.0, they may be incompatible with JDK 1.2/Swing 1.1 objects. 3.3.2.10 Debug Graphics Lightweight components are rendered entirely in Java, as opposed to off-loading their work to a native heavyweight peer. The abstract Graphics class outlines platform-independent implementations for line-drawing, image-painting, and area-copying and filling that a lightweight peer can call upon to draw itself. If you create your own component, or extend an already existing one, a Graphics object is often passed to the UI delegate’s paint() method to help out with the drawing. Sometimes the way you intend a component to be painted, however, isn’t how it appears on the screen. Debugging painting problems can prove to be troublesome, especially when dealing with transparency, opaqueness, and double buffering. JComponent, however, can generate a special version of the Graphics object, called DebugGraphics , which it can pass to a UI delegate’s paint() method that aids in debugging. This object can take a set of user-configurable debugging options that modify how a component is drawn to the screen. - 64 -
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Java Swing O Reilly tooltip by declaring your (Web host forum)

Monday, July 30th, 2007

Java Swing O Reilly tooltip by declaring your own JToolTip object and overriding the createToolTip() method of JComponent to return it to the ToolTipManager on demand. We cover the JToolTip object and the ToolTipManager in more detail in Chapter 27. 3.3.2.7 Client Properties Swing components can maintain a special table of properties called “client properties.” The purpose is to provide specialized properties that can be meaningful in components only in certain instances. For example, let’s assume that a specific look-and-feel uses a client property to store information about how a component should display itself when that L&F is activated. As you might guess, this client property would be meaningless when another look-and-feel is activated. Using the client properties approach allows various look-and-feels to expand their component properties without deluging the Swing source base with L&F-specific data. The name “client properties” is somewhat confusing, because client properties are distinct from JavaBeans-style properties. Obviously, there’s a big difference: unlike JavaBeans properties, you can create new client properties without subclassing; you can even create new client properties at runtime. These two methods in JComponent store and retrieve client properties: myComponent. putClientProperty(”aClientProperty”, Boolean.TRUE); Boolean result = (Boolean)getClientProperty(”aClientProperty”); Note that because we are using a hashtable, the properties must be objects and not primitive data types. Hence, we are forced to use the Boolean object, instead of simplysetting true and false. 3.3.2.8 Double Buffering The JComponent class allows all Swing components to take advantage of double buffering. The idea behind double buffering is that it takes longer for a component to render its individual parts on screen than it does for a rectangular area-copy to take place. If the former occurs with multiple refreshes, the human eye is likely to catch the component in the process of being drawn, and it may appear to flicker. With the latter, the screen is usually updated as fast as the monitor can refresh itself.[3] [3] Area copies are always faster because they are performed by the operating system or even the graphics card of the computer. At this level, they are commonly referred to as “bit-block transfers” or BitBLTs. When double buffering is activated in Swing, all component rendering performed by the repaint manager is done to an off-screen buffer. Upon completion, the contents of the off-screen buffer are quickly copied (not redrawn) on the screen at the component’s position. You can activate double buffering by accessing the boolean doubleBuffered property of JComponent. Passing in true to the setDoubleBuffered() method enables double buffering; false shuts it off: JButton button = new JButton(”Test Button”); button.setDoubleBuffered(true); // Turns on double buffering You can use the isDoubleBuffered() method to check if double buffering is currently enabled on a Swing component. - 63 -
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Web hosting services - Java Swing O Reilly component with multiple borders

Sunday, July 29th, 2007

Java Swing O Reilly component with multiple borders through the use of the CompoundBorder class. This class allows you to combine any two borders into a single border by specifying one as the outer border and the other as the inner. Because CompoundBorder accepts other compound borders, you can recursively layer as many borders as you like into a single border. Using borders is extremely easy. For example, one of the border styles that is provided with Swing is an etched border. Here is how you might create a bevel border similar to the one in Figure 3.7: JLabel label = new JLabel(”A Simple Label”); label.setBorder(new EtchedBorder()); One important characteristic of Swing is that if a border property is set on a component, the border overrides the component’s insets property. Swing allows the programmer to specify an empty border, so you can still pad the component with extra space as well as provide a border if you use a CompoundBorder. If the border property is null, the default insets are used for the component instead. Borders are covered in more detail in Chapter 13. 3.3.2.6 Working with Tooltips JComponent also provides Swing components with support for tooltips. Tooltips are small windows of text that pop up when the user rests the mouse over the target component. They are typically used to supplement the meaning of an icon or button, but they can also provide the user with instructions or important information about the underlying component. The tooltip usually disappears after a designated amount of time (four seconds by default) or if the mouse is moved outside of the component’s bounds. Simple string-based tooltips can be automatically set or retrieved using the toolTipText property of JComponent, as shown here: JButton button = new JButton(”Press Me!”); // JButton extends JComponentbutton.setToolTipText(”Go Ahead!”); System.out.println(button.getToolTipText()); Figure 3.8 shows what a tooltip looks like on the screen. Figure 3.8. A tooltip for a component JComponent does not manage tooltips by itself; it gets help from the ToolTipManager class. The ToolTipManager continually scans for mouse events on components that have tooltips. When the mouse passes into a component with a tooltip set, the ToolTipManager begins a timer. If the mouse has not left the component’s region in three-quarters of a second, a tooltip is drawn at a preset location near the component. If the mouse has moved out of a region for longer than a half-second, the tooltip is removed from the screen. With the default setToolTipText() and getToolTipText() methods, JComponent handles the creation of an appropriate tooltip. If you want to get more creative, however, Swing provides a separate object for tooltips: JToolTip. With it, you can completely redefine the characteristics of a - 62 -
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Java Swing O Reilly System.out.println(”X = ” +

Sunday, July 29th, 2007

Java Swing O Reilly System.out.println(”X = ” + frame.getX()); System.out.println(”Y = ” + frame.getY()); System.out.println(”Width = ” + frame.getWidth()); System.out.println(”Height = ” + frame.getHeight()); In addition, if it is just the size or location you are concerned with, you can use the getSize() and getLocation() accessors to set or retrieve the size or location. The size is specified as a Dimension, while the location is given as a Point. Like getBounds(), the getLocation() accessor also allows the programmer to pass in a pre-instantiated Point object. If one is passed in, the method alters the coordinates of the Point instead of instantiating a new object. Point myPoint = new Point(); myPoint = component.getLocation(myPoint); You can still use the setSize() and setLocation() methods of java.awt. Component if you prefer to code with those as well. Again, note that when resetting the size of the component, the layout manager may override the new value and reset it back to its previous value, thus ignoring your new size values. The three well-known AWT sizing properties, minimumSize , preferredSize , and maximumSize , are accessible through JComponent. minimumSize indicates the smallest size that the component is allowed to be when it exists in a container. preferredSize contains the size at which the container’s layout manager should strive to draw the component. maximumSize indicates the largest size the component should be when displayed in a container. If none of these properties are set by the user, they are always calculated by the component’s UI delegate or directly by the layout manager of the container, in that order. An important new feature of JComponent is the addition of the methods setMinimumSize(), setPreferredSize, and setMaximumSize(), allowing you to change these properties without subclassing. Finally, JComponent contains two read/write properties that help interested layout managers align the component in a container: alignmentX and alignmentY. Both of these properties contain floating-point values between 0.0 and 1.0; the numbers determine the position of the component relative to any siblings. A number closer to indicates that the component should be positioned closer to the left or top side, respectively. A perfect 0.5 indicates that the component should be placed at the center, while a number nearing 1 indicates that the component should be positioned closer to the right or bottom. Currently, the only layout managers that use these properties are the BoxLayoutand OverlayLayout managers; all AWT 1.1 layout managers ignore these properties and position their children by other means. We discuss these managers further in Chapter 11. 3.3.2.5 Adding Borders One widely requested feature of AWT is the ability to provide components with borders. Swing has defined a border property in JComponent that accepts objects that implement the javax.swing.border.Border interface. Figure 3.7 shows a component with a border. Figure 3.7. Borders in Swing Swing currently provides seven different styles of borders, including an empty border. Each one extends the javax.swing.border.Border interface. In addition, you can surround a Swing - 61 -
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Java Swing O Reilly Unlike the AWT Component

Saturday, July 28th, 2007

Java Swing O Reilly Unlike the AWT Component class, the getBounds() accessor in JComponent can take a pre- instantiated Rectangle object, as shown below: Rectangle myRect = new Rectangle(); myRect = component.getBounds(myRect); If a Rectangle is supplied, the getBounds() method alters each of the fields in the passed-in Rectangle to reflect the component’s current size and position, returning a copy of it. If the reference passed in is a null, the method instantiates a new Rectangle object, sets its values, and returns it. You can use the former approach to conserve memory if there are several calls to getBounds(). The setBounds() method resets the component’s size and position. This method also takes a Rectangle object. If the new settings are a change from the previous settings, the component is moved, typically resized, and invalidated. If the component has a parent, it is invalidated as well. Be warned that various layout managers may override any changes you attempt to make to the bounds property. Invalidating a component with a call to setBounds() may force the layout manager to recompute and reset the bounds of the component in relation to the other components resolving it to the same size as before. Here is a short example that shows how to retrieve the current position and size of any Swing component: JFrame frame = new JFrame(”Test Frame”); frame.setBounds(20,20,200,200); frame.setVisible(true); Rectangle r = new Rectangle(); r = frame.getBounds(r); System.out.println(”X = ” + r.x()); System.out.println(”Y = ” + r.y()); System.out.println(”Width = ” + r.width()); System.out.println(”Height = ” + r.height()); There is a shorthand approach for retrieving each of the bounds properties. JComponent contains four methods that directly access them: getX() , getY(), getWidth(), and getHeight(). You can use these accessors directly instead of instantiating a Rectangle object on the heap with a call to getBounds(). Consequently, you can replace the last six lines with the following four: - 60 -
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Java Swing O Reilly The visibleRect property is (Tomcat web server)

Saturday, July 28th, 2007

Java Swing O Reilly The visibleRect property is a Rectangle that indicates the intersection of the component’s visible rectangles with the visible rectangles of all of its ancestors. Why the intersection? Remember that you can have a contained object that is clipped by its parent. For example, you can move an internal frame so that a portion of it falls outside the parent window’s clipping region. Therefore, the visible portion (the portion that is actually drawn to the screen) will consist only of the intersection of the parent’s visible portion and the child’s visible portion. You typically will not need to access this property. The validateRoot property is false by default. If it is set to true, it designates this component as the root component in a validation tree. Recall that each time a component in a container is invalidated, its container is invalidated as well, along with all of its children. This causes an invalidation to move all the way up the component hierarchy, stopping only when it reaches a component for which isValidateRoot() returns true. Currently, the only components that set this property to true are JRootPane (which is used by all the Swing top-level components), JScrollPane, and JTextField. The topLevelAncestor property contains a reference to the top-level window that contains this component, usually a JWindow or JApplet. The rootPane property contains the low-level JRootPane for this component; JRootPane is covered in more detail in Chapter 8. Finally, JComponent contains a property called autoscrolls , which indicates whether a component is capable of supporting autoscrolling. This property is false by default. If the property is true, an Autoscroller object has been set over this component. The Autoscroller object monitors mouse events on the target component. If the mouse is dragged outside the component, the autoscroller will force the target component to scroll itself. Autoscrolling is typically used in containers such as JViewport. 3.3.2.4 Position, Size, and Alignment You can set and retrieve a Swing component’s current position and size on the screen through the bounds property, or more precisely, through the location and size properties of JComponent. The location property is defined as a Point in the parent’s coordinate space where the upper-left corner of the component’s bounding box resides. The size property is a Dimension that specifies the current width and height of the component. The bounds property is a Rectangle object that gives the same information: it bundles both the location and the size properties. Figure 3.6 shows how Swing measures the size and location of a component. Figure 3.6. Working with the bounds, size, and location properties - 59 -
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Java Swing O Reilly however, does not end (Free web hosting with ftp)

Friday, July 27th, 2007

Java Swing O Reilly however, does not end there. JComponent is actually responsible for painting three items: the component itself, any borders associated with the component, and any children that it contains. The order is intentional. Swing assumes that the components drawn last are always on top; hence, child components always paint over their parents. JComponent contains three protected methods that it uses to complete this functionality: paintComponent() paintBorder() paintChildren() Because of the complexity involved in painting and repainting Swing components, you should always try to override these three methods while creating your own components. Again, do not try to override paint() unless you call superpaint() while you’re at it. The boolean property opaque dictates the transparency of each Swing object.[2] If this property is set to false, the component’s background color is transparent. This means that any areas left untouched by the component’s rendering allow graphics in the background to show through. If the property is set to true, the rectangular painting region is completely filled with the component’s background color before it is rendered. Incidentally, transparency was not possible before lightweight components. Native peer objects in Java 1.0 always drew their component on a solid rectangle; anything that was behind the component was erased. Figure 3.5 shows the difference between an opaque and a transparent (non-opaque) label without a dark background color. The label on the left is transparent, so its background color is ignored; the label’s text appears on top of the container’s relatively light background. [2] In JDK1.2, the isOpaque() method is defined in java.awt.Component. Figure 3.5. Transparency and opaqueness JComponent can optimize its repainting time if none of its children overlap; this is because the repaint manager does not have to compute the hidden and visible areas for each child component before rendering them. Some containers, such as JSplitPane, are designed so that overlap between child components is impossible, so this optimization works nicely. Other containers, such as JLayeredPane, have support for child components that can overlap. JComponent contains a property that Swing frequently calls upon to see if it can optimize component drawing: optimizedDrawingEnabled . In JComponent, the property is set to true by default. If overlap occurs in a subclass of JComponent, the subclass should override the isOptimizedDrawingEnabled() accessor and return false. This prevents the repaint manager from using the optimized drawing process when rendering the container’s children. JComponent contains a boolean read-only property paintingTile that indicates whether the component is currently in the process of painting a tile that is, a child component that does not overlap any other children. The isPaintingTile() method will return true until all tiles have been painted. - 58 -
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Java Swing O Reilly Swing uses a repaint (Web site layout)

Friday, July 27th, 2007

Java Swing O Reilly Swing uses a repaint manager to repaint lightweight components. The repaint manager maintains a queue of rectangular areas that need to be repainted; it calls these areas ” dirty regions.” Sometimes the rectangles are the size of entire components; other times they are smaller. The repaint manager processes repaint requests as they are added to the queue, updating dirty regions as quickly as possible while preserving the visual order of the components. Recall that in AWT, the Componentclass contains an overloaded repaint() method that allows you to repaint only a subrectangle of the component. The same is true with JComponent. If only part of a component needs to be repainted, the repaint manager invokes an overloaded version of the repaint() method that takes a Rectangle parameter. JComponent contains two repaint() methods that each add specified rectangles directly to the dirty region. Like AWT, you want call upon these methods instead of invoking the paint() method directly, which bypasses the RepaintManager. The RepaintManager class is discussed in more detail in Chapter 28. 3.3.2.3 The paint( ) Method and Opaqueness Because JComponent is the direct subclass of the AWT Container class, it is the official recipient of repaint requests through its paint() method. As you might guess, JComponent must delegate this request by passing it on to the paint() method of the UI-delegate object. The responsibility, - 57 -
Check Tomcat Web Hosting services for best quality webspace to host your web application.