Archive for April, 2007

Web site builder - Java Swing O Reilly public void removeNotify() Called

Sunday, April 29th, 2007

Java Swing O Reilly public void removeNotify() Called by Swing to notify the component that it has lost a parent. The method fires a notification to all AncestorListeners, informing them that the parent component is no longer an ancestor. removeNotify() also fires a property change event indicating that the “ancestor”property has changed. public void scrollRectToVisible(Rectangle aRect) Calls similar methods up the component hierarchy. You can override this method at any level if you want to explicitly handle scrolling updates. public static boolean isLightweightComponent(Component c) A convenience method that returns a boolean indicating whether the component passed is a lightweight component. If it is, the method returns true. Otherwise, it returns false. This method may move to java.awt.Component in the future. Chapter 4. Labels and Icons We’ll begin our look at the Swing components with the JLabel class. In addition, we’ll look at Swing’s new Icon interface and an implementation of this interface called ImageIcon. With just these few new constructs, you’ll begin to see how much Swing has done to improve UI development in Java. 4.1 Labels Swing allows you to create labels that can contain text, images, or both. We’ll begin this chapter with a look at the JLabel class. 4.1.1 The JLabel Class The JLabel class allows you to add basic, nonfunctional labels to a user interface. Because of their inherent simplicity, there is no model class for JLabel components. Figure 4.1 shows a class diagram for JLabel. We’ll get into the two relations to Icon a little later. Figure 4.1. JLabel class diagram - 74 -
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services

My web site - Java Swing O Reilly public final void putClientProperty(Object

Sunday, April 29th, 2007

Java Swing O Reilly public final void putClientProperty(Object key, Object value) Inserts the specified client property value under the appropriate key. If the value passed in is null, the property is cleared from the list. 3.3.4.8 Event Handlers protected void processFocusEvent(FocusEvent e) Sets an internal flag that indicates whether the JComponent has gained or lost the focus. You can override this method in a subclass to determine how your component reacts to super.processFocusEvent(). protected void processComponentKeyEvent (KeyEvent e) This method currently does nothing. You can override it if you want to handle KeyEvents in your component independent of those consumed by the focus handler and key listeners. If you handle any KeyEvent notifications in this method, be sure to consume them. protected void processKeyEvent(KeyEvent e) Handles the key events for each component. It first checks with the focus manager to see if it can consume the key event, then checks for any interested listeners, and (if it has not been consumed) invokes the processComponentKeyEvent() above. If the key event still has not been consumed at this point, it will check to see if there are any keyboard actions registered with the component. protected void processMouseMotionEvent(MouseEvent e) Tracks mouse drags in the event that the Swing component supports autoscrolling. You can override this method in a subclass to determine how your component reacts to mouse motion events. If you do so, be sure to call super.processMouseMotionEvent(). 3.3.4.9 Miscellaneous protected void setUI(ComponentUI u) Installs u as the UI delegate for the component, effectively changing the component’s look- and-feel. This change doesn’t appear onscreen until updateUI() is called. public void updateUI() Called by the current UIManager to notify the component that the look-and-feel for the component has changed, and the UI delegate should repaint itself. public void addNotify() Called by Swing to notify the component that it has gained a parent. The method fires a notification to all AncestorListeners, passing in a reference to the new parent component. The parent component (and its ancestors) inherit each of the appropriate keyboard actions and AWT event masks, as appropriate. addNotify() also fires a property change event indicating that the “ancestor” property has changed. - 73 -
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services

Java Swing (Simple web server) O Reilly actionPerformed() method of the

Sunday, April 29th, 2007

Java Swing O Reilly actionPerformed() method of the object implementing anAction. If the programmer desires, the action command can be set to aCommand. The conditions involved are listed in Table 3.7. public void unregisterKeyboardAction(KeyStroke aKeyStroke) Unregisters a keyboard action from the component. public int getConditionForKeyStroke(KeyStroke aKeyStroke) Returns the conditions defined for the keyboard action triggered by aKeyStroke. public ActionListener getActionForKeyStroke(KeyStroke aKeyStroke) Returns the Action that is registered to be triggered by aKeyStroke. public void resetKeyboardActions() Clears all keyboard actions for the component. protected void processComponentKeyEvent(KeyEvent e) This protected method is called if there are no keyboard actions matching the keystroke directed at the component. The method currently does nothing; you can override it in your own components to perform component-specific keyboard handling. 3.3.4.6 Tooltips public String getToolTipText(MouseEvent event) Retrieves the text used for the component’s tooltip, given the appropriate mouse event. JComponent always returns the current toolTipText property. However, you can override this method in your own component if you want to return different strings based on various mouse events. public Point getToolTipLocation(MouseEvent event) Currently returns null. You can override it in your own component to specify the local component coordinates where its tooltip should be displayed. If the method returns null, Swing chooses a location for you. public JToolTip createToolTip() Returns a new instance of JToolTip by default. If you want to extend the JToolTip class with a tooltip creation of your own, you can override this method in your components, forcing it to return the new class to the tooltip manager. 3.3.4.7 Client Properties public final Object getClientProperty(Object key) Searches the client property list for the Object specified under the appropriate key. It returns null if no object is found. - 72 -
Note: In case you are looking for affordable webhost to host and run your web application check Vision http web server services

Java Swing O Reilly component layers, it is (Tomcat web server)

Saturday, April 28th, 2007

Java Swing O Reilly component layers, it is widely preferred that you call these methods, instead of directly invoking paint(). public void paintImmediately(int x, int y, int w, int h) public void paintImmediately(Rectangle r) These methods force an immediate repaint of the specified region in the component. This method is invoked by the repaint manager when it is time for the component to draw itself; the programmer should not call this method. This method may move to java.awt.Component in the future. public void revalidate() Adds the current component to the repaint manager’s revalidation queue, which is located on the system event queue. public void computeVisibleRect(Rectangle visibleRect) Calculates a Rectangle that represents the intersection of the component’s own visible rectangle and each of its ancestors. The result is placed in the visibleRect property and is used to determine how much of a component is drawn to the screen. 3.3.4.4 Focus public void requestFocus() Shifts the focus to this component if the requestFocusEnabled property is true. public boolean requestDefaultFocus() Shifts the focus to a default component, typically the first focus-traversable component in the current container. If the method is unable to find such a component, it returns false. public void grabFocus() Used by focus managers to shift the focus to this component, regardless of the state of the requestFocusEnabled property. Because of this, it is generally better to use requestFocus() instead of this method. public boolean hasFocus() Returns true if this component currently has the focus. This method is defined in java.awt.Component in JDK 1.2. 3.3.4.5 Keyboard Actions public void registerKeyboardAction(ActionListener anAction, String aCommand,KeyStroke aKeyStroke, int aCondition) public void registerKeyboardAction(ActionListener anAction, KeyStroke aKeyStroke,int aCondition) These methods register a specific keyboard action with the component. When the keystroke aKeyStroke occurs under the appropriate conditions, JComponent invokes the - 71 -
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision professional web hosting services

Web site translator - Java Swing O Reilly Equivalent to paint(g). This

Saturday, April 28th, 2007

Java Swing O Reilly Equivalent to paint(g). This is significantly different from the update() method of Component, which first cleared the component’s background. In Swing, clearing the component is handled by ComponentUI, based on whether the component is opaque. public boolean contains(int x, int y) Returns true if the coordinates passed in are inside the bounding box of the component, false otherwise. The method always asks the UI delegate first, giving it an opportunity to define the bounding box as it sees fit. If the UI delegate does not exist for this component, or cannot define the bounding box, the standard component contains() method is invoked. publicInsets getInsets (Insets insets) Copies the JComponent’s insets into the given Insets object, and returns a reference to this object. public void paint(Graphics g) The primary method that the AWT subsystem calls upon for components to draw themselves if they are not obscured. This method delegates most of its work to the protected methods paintComponent(), paintBorder(), and paintChildren(), which it calls in that order. Because this method performs its own internal calculations, it is generally not a good idea to override it in a subclass; if you want to redefine how a component draws itself, override paintComponent() instead. public void reshape(int x, int y, int w, int h) Resets the bounds property of the component. protected void paintComponent(Graphics g) Draws the component using the graphics context provided. Unless overridden, it simply turns around and calls the paint() method of the delegate. If there is no delegate, the method does nothing. protected void paintChildren(Graphics g) Cycles through each of the component’s children, invoking the paint() method on each one. protected void paintBorder(Graphics g) Paints the border (or borders) outlined in by the border property of JComponent. Note that if a border is defined, JComponent ignores its own insets and uses the border instead. public void repaint(long tm, int x, int y, int width, int height) public void repaint(Rectangle r) These methods place a request to repaint the specified region on the repaint manager’s update queue. The initial variable tm of the first repaint() method is no longer used and can be ignored. Because the redrawing queue knows the correct order to draw various - 70 -
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision professional web hosting services

Java Swing O Reilly Add and (Web site templates) remove a

Saturday, April 28th, 2007

Java Swing O Reilly Add and remove a VetoableChangeListener to the event registration list. A VetoableChangeListener is allowed to veto any property changes that occur inside a component. If only one veto occurs, the property is not changed. public void addAncestorListener(AncestorListener listener) public void removeAncestorListener(AncestorListener listener) Add and remove an AncestorListener to the event registration list. All registered objects are notified if any of the components’ ancestors change position or are made visible or invisible. JComponent also inherits all the event listener registration methods from its AWT superclasses, Container and Component. From Component, it inherits the methods to add or remove a ComponentListener, FocusListener, KeyListener, MouseListener, or MouseMotionListener. From Container, it inherits the methods to add or remove a ContainerListener. We won’t describe all the listener interfaces here; for more information, see Java AWT by John Zukowski (O’Reilly). However, you should note that Swing only supports the JDK 1.1 event model. To receive an event, you always must register as a listener with the JComponent that generates the event events are never propagated through the containment hierarchy, as they were with JDK 1.0. 3.3.4 Fields and Methods 3.3.4.1 Protected Fields protected AccessibleContext accessibleContext Holds the AccessibleContext for the component. protected EventListenerList listenerList The event listener list for the component. See Chapter 27 for more information on the EventListenerList class. protected ComponentUI ui The UI delegate for the component. 3.3.4.2 Constructor public JComponent() Initializes a simple JComponent and sets the layout manager to null. 3.3.4.3 Graphics protected Graphics getComponentGraphics(Graphics g) Accepts a graphics context and modifies its foreground color and font to match the current defaults. If the debug graphics option has been activated, the method returns a special graphics object that the programmer can configure for debugging component drawing with the color and font modifications. public void update(Graphics g) - 69 -
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision j2ee hosting services

Java Swing O Reilly The accessibleContext (Web hosting isp) property holds

Friday, April 27th, 2007

Java Swing O Reilly The accessibleContext property holds an AccessibleContext object that is the focal point of communication between the component and auxilliary accessibility tools. There’s a different default context for each kind of JComponent. For nore information, see Chapter 25. 3.3.3 Events Table 3.8 shows the events fired by JComponent (not counting the many events it inherits from the AWT classes). Table 3.8, JComponent Events Event Description PropertyChangeEvent A change has occurred in JComponent. A change has occurred in JComponentthat can be vetoed by interested VetoablePropertyChangeEvent listeners. AncestorEvent An ancestor of a JComponent has moved or changed its visible state. 3.3.3.1 Event Methods The following methods may move to java.awt.Component in the future. protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) public void firePropertyChange(String propertyName, byte oldValue, byte newValue) public void firePropertyChange(String propertyName, char oldValue, char newValue) public void firePropertyChange(String propertyName, short oldValue, short newValue) public void firePropertyChange(String propertyName, int oldValue, int newValue) public void firePropertyChange(String propertyName, long oldValue, long newValue) public void firePropertyChange(String propertyName, float oldValue, float newValue) public void firePropertyChange(String propertyName, double oldValue, double newValue) public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) Fire a PropertyChangeEvent to all registered listeners if newValue differs from oldValue. There are overloaded versions of this method for each primitive data type, as well as a protected version for the generic Object class. protected void fireVetoableChange(String propertyName, Object oldValue, Object newValue) throws PropertyVetoException Fires a vetoable PropertyChangeEvent to all registered listeners if newValue differs from oldValue. public synchronized void addPropertyChangeListener(PropertyChangeListener listener) public synchronized void removePropertyChangeListener(PropertyChangeListener listener) Add and remove a PropertyChangeListener to the event registration list. public synchronized void addVetoableChangeListener(VetoableChangeListener listener) public synchronized void removeVetoableChangeListener(VetoableChangeListener listener) - 68 -
Note: If you are looking for reliable webhost to maintain and run your java application check Vision java hosting services

Frontpage web hosting - Java Swing O Reilly You can associate keyboard

Friday, April 27th, 2007

Java Swing O Reilly You can associate keyboard actions to a component through one of two registerKeyboardAction() methods: void registerKeyboardAction(ActionListener anAction, String aCommand, KeyStroke aKeyStroke, int aCondition) void registerKeyboardAction(ActionListener anAction, KeyStroke aKeyStroke, int aCondition) In order to use these methods, you need a couple of things: a KeyStroke object that represents the keystroke combination you wish to monitor, and an Action that occurs when that keystroke has taken place. (Actions are covered earlier in the chapter.) If you want the keyboard event to insert a specific string as the event’s action command, you can specify that as well. A final parameter to the registerKeyboardAction() method places restrictions on when the action is fired. Table 3.7 shows the constants for the final parameter. Table 3.7, Constants for Keystroke Registration Constant Description WHEN_FOCUSED The Action takes place only when the target component has the focus. The Action takes place when the target component has the focus or WHEN_IN_FOCUSED_WINDOW resides in a container that has the focus. The Action takes place when the target component has the focus, or is WHEN_ANCESTOR_OF_FOCUSED_WINDOW the ancestor of the component that currently has the focus. The latter two constants come in handy in different situations. JComponent.WHEN_IN_FOCUSED_WINDOW can be used in a situation where you want to define a keystroke that works on a specific component in a container, but functions even when the parent container has the focus. For example, a dialog could have a save button that captures the letter “S” in conjunction with a modifier key (ALT, CTRL, or SHIFT). It could register this keyboard action with the button to perform a save when the “S” key was pressed. The keyboard action would work even if the button didn’t explicitly have the focus as long as the parent dialog did. On the other hand, if you want to define a keyboard event that is standardized throughout a container and its components, register a keyboard event at the container level and use the JComponent.WHEN_ANCESTOR_OF_FOCUSED_WINDOW option. This allows keyboard events to be recognized at the container level, even if the descendant has the focus. You can use the registeredKeyStrokes property of JComponent to get access to all the keystrokes registered for a component. The getRegisteredKeyStrokes() method returns this information as an array of KeyStroke objects. If you want to see what condition is tied to any particular keystroke, you can use the getConditionForKeyStroke() method. If you want to obtain the action associated with the keystroke, use getActionForKeyStroke() . In both cases, you will have to specify the target keystroke as the search key. 3.3.2.13 Accessibility As we mentioned in Chapter 1, one entirely new feature about Swing components is that they support accessibility options. Accessibility options are constructed for users who have trouble with traditional user interfaces, and include support for alternative input and output devices and actions. There are several parts to accessibility; they are covered in more detail in Chapter 25, and Chapter 26. JComponent implements the methods required by the Accessible interface, though it does not implement the interface itself. - 67 -
Note: In case you are looking for affordable webhost to host and run your web application check Vision cheap hosting services

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

Friday, April 27th, 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 -
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision servlet hosting services

Java Swing O Reilly If (Web server type) you wish to

Friday, April 27th, 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 -
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision j2ee hosting services