January 29th, 2008
Java Swing - O Reilly public void registerComponent(JComponent component) Registers component with the ToolTipManager to make sure that its tips get shown after an appropriate mouse event occurs. public static ToolTipManager sharedInstance() Returns the global ToolTipManager. You can use this to get access to the manager and changes its delay properties. For example, you could cut the initial delay to 250 milliseconds like this: ToolTipManager.sharedInstance().setInitialDelay(250); public void unregisterComponent(JComponent component) Unregisters component from the ToolTipManager. Tooltips will no longer be shown for this component. 27.1.5 The JToolTip Class Of course, the whole purpose of having a tooltip manager is to manage tooltips. The tooltips themselves are simple popups containing a short, descriptive string that often shows up if you let your mouse cursor rest too long over a component. They are embodied here in the JToolTip class. JToolTip is a fairly simple class, thanks to the MVC architecture in place for Swing. All it really needs to know is what text to display, and who to display it for. 27.1.5.1 Properties The properties that support the JToolTip class are shown in Table 27.4. The component property determines which component this tip applies to. The tipText property contains the text to display for the tip. Both of these properties are currently stored in package private variables. Table 27.4, JToolTip Properties Property Data Type get is set bound Default Value UI* TreeUI From L&F UIClassID* String “ToolTipUI” accessibleContext AccessibleContext JToolTip.Accessible-JToolTip() component Component null tipText String null 27.1.5.2 Constructor The JToolTip class has only one constructor: public JToolTip() This creates a new JToolTip object with no text or component association. 27.1.5.3 UI Method public void updateUI() - 922
In case you need quality webspace to host and run your web applications, try our personal web hosting services.
Posted in Blue | No Comments »
January 28th, 2008
Java Swing - O Reilly dismissDelay int 4000 enabled boolean true initialDelay int 750 lightWeightPopupEnabled[1] boolean true reshowDelay int 500 [1] Deprecated as of Swing 1.1/JDK1.2 beta4. 27.1.4.2 Fields protected boolean lightWeightPopupEnabled Stores the value of the lightWeightPopupEnabled property. Deprecated in Swing 1.1/JDK1.2 beta4. protected boolean heavyWeightPopupEnabled This field is used to help manage heavyweight (not bound by window constraints) tooltips. It is initially set to false. 27.1.4.3 Mouse Event Methods public void mouseDragged(MouseEvent event) This method is empty. (By definition, you can’t drag a tool tip.) public void mouseEntered(MouseEvent event) Gets the system ready to show the tooltip text (if any exists) in initialDelay milliseconds. public void mouseExited(MouseEvent event) Checks to make sure you’re really exiting the component (you could be mousing out of the component but into the tooltip, for example), and if so, hides the popup and starts the reshow countdown. public void mouseMoved(MouseEvent event) Monitors your movements and keeps tips active as you move from one component to the next (so that they show up immediately). public void mousePressed(MouseEvent event) Hides the popup and stops the timer watching for the initialDelay to pass. 27.1.4.4 Miscellaneous Methods If need be, you can manually register or unregister components with the manager. Normally this is done using the JComponent.setToolTipText() method for the component itself. If you pass in a non-null tip string, the component is registered. If you pass in a null tip string, the component is unregistered. - 921
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.
Posted in Blue | No Comments »
January 28th, 2008
Java Swing - O Reilly super(”" + new Date()); Timer t = new Timer(1000, this); t.start(); } public void actionPerformed(ActionEvent ae) { setText(”" + new Date()); } } And here’s the application that displays the ClockLabel object: // ClockTest.java // A demonstration framework for the Timer driven ClockLabel class. // import javax.swing.*; import java.awt.*; public class ClockTest extends JFrame { public ClockTest() { super(”Timer Demo”); setSize(300, 100); addWindowListener(new BasicWindowMonitor()); ClockLabel clock = new ClockLabel(); getContentPane().add(clock, BorderLayout.NORTH); } public static void main(String args[]) { ClockTest ct = new ClockTest(); ct.setVisible(true); } } 27.1.4 The ToolTipManager Class This class manages the tooltips for an application. Any given virtual machine will have, at most, one ToolTipManager at any time a new instance is created when the class is loaded. You can retrieve the current manager using the ToolTipManager.sharedInstance() method. 27.1.4.1 Properties The ToolTipManager properties shown in Table 27.3 give you control over the delays (in milliseconds) involved in showing tooltips and determines whether or not tooltips are even active. The enabled property determines whether or not tooltips are active. The dismissDelay determines how long a tootip remains on the screen if you don’t do something to dismiss it manually (such as move the mouse outside the component’s borders). The initialDelay determines how long the mouse must rest inside a component before the tooltip pops up, and the reshowDelay determines how long you must wait after leaving a component before the same tooltip will show up again when you re-enter the component. If the lightWeightPopupEnabled property is true, all-Java tooltips will be used. A false value indicates native tooltips should be used. Table 27.3, ToolTipManager Properties Property Data Type get is set bound Default Value - 920
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.
Posted in Blue | No Comments »
January 28th, 2008
Java Swing - O Reilly The list of listeners interested in receiving notification each time the timer generates an event. 27.1.3.4 Constructor public Timer(int delay, ActionListener listener) Creates a Timer object that notifies its listener every delay milliseconds. The listener argument can be null. The timer is not started right away; you must manually call the start() method. 27.1.3.5 Timer Control Methods You also have a few methods to control the timer at runtime: public void start() Starts the timer. The first event comes after initialDelay milliseconds, and if it’s a repeating timer, every delay seconds after that. public void restart() Restarts the timer. This method calls stop() and then start(). public void stop() Stops the timer. Any timer events that have not yet been fired will be deleted. Figure 27.2 shows a ClockLabel that updates itself every minute, using events from a Timer. The code to prouce our ticking label is remarkably short when we use a Timer. Figure 27.2. The Timer class in action with a ClockLabel // ClockLabel.java // An extension of the JLabel class that listens to events from // a Timer object to update itself with the current date & time. // import java.util.*; import java.awt.event.*; import javax.swing.*; public class ClockLabel extends JLabel implements ActionListener { public ClockLabel() { - 919
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.
Posted in Blue | No Comments »
January 27th, 2008
Java Swing - O Reilly 27.1.3 The Timer Class The Timer class behaves like an invisible component. It has properties and events, and thus can be used in application builders that understand JavaBeans. Its purpose is to fire an ActionEvent at a given time. The event can be set to repeat, and an optional initial delay can be set before the repeating event starts. 27.1.3.1 Properties The Timer class properties give you access to the timer delays and nature of the event firing loops. They are listed in Table 27.2. The delay property dictates the length between repeated timer events (if repeats is true) and initialDelay determines how long to wait before starting the regular, repeating events. If your timer is not repeating, then the value of initialDelay determines when the timer fires its event. You can check to see if the timer is running with the running property. The coalesce property dictates whether or not the timer will combine pending events into one single event (to help listeners keep up). For example, if the timer fires a tick every 10 milliseconds, but the application is busy and has not handled events for 100 milliseconds, 10 action events are queued up for delivery. If coalesce is false, all 10 of these will be delivered in rapid succession. If coalesce is true (the default) only one event will be fired. The logTimers property can be turned on to generate simple debugging information to the standard output stream, each time an event is processed. Table 27.2, Timer Propertiessv Property Data Type get is set bound Default Value delay int from constructor coalesce boolean true initialDelay int this.delay logTimers boolean false repeats boolean true running boolean false 27.1.3.2 Events A Timer generates an ActionEvent whenever it “goes off.” You can listen for ActionEvent if you want to react to a timer tick. public void addActionListener(ActionListener l) public void removeActionListener(ActionListener l) Add and remove listeners interested in receiving action events from the timer. The Timer class also contains its own fireActionPerformed() method to facilitate event reporting if you subclass Timer. protected void fireActionPerformed(ActionEvent e) Sends ActionEvent objects to any registered listeners. 27.1.3.3 Fields protected EventListenerList listenerList - 918
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.
Posted in Blue | No Comments »
January 27th, 2008
Java Swing - O Reilly Lays out a label with text and an icon, using the font metrics, alignments, and text positions supplied relative to the viewR rectangle. If text cannot be contained in the label, it is truncated and “…” is appended. The resulting string is returned; textR and iconR are updated to contain the coordinates required to accomplish the desired layout. public static void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h) public static void paintComponent(Graphics g, Component c, Container p, Rectangle r) Paint the component c in an arbitrary graphics object g, bounded by the given rectangle, r. The container p is set as the new parent of c to stop the propagation of any validate() or repaint() calls to c. This is an easy way to rubber-stamp a component’s image on a graphics area. For example, you might want to use this method in a tree or table cell renderer to draw “read-only” versions of components such as sliders. The image would look like a slider, but would just be an image, not a real component. public static void updateComponentTreeUI(Component c) Tells all components contained below c to update their current UI. public static Window windowForComponent(Component aComponent) This convenience method returns the Window object containing aComponent. If no containing window is found, null is returned. 27.1.2 The SwingConstants Interface This interface defines the location constants shown in Table 0-1 that are used throughout the Swing package. Quite often, this interface is implemented by a component so that the constants appear as regular parts of the class for ease of use. (The JLabel and SwingUtilities classes are examples of such classes.) Table 27.1, SwingConstants Constants Constant Type Description BOTTOM int Bottom location CENTER int Center location or justification EAST int East (compass) location HORIZONTAL int Horizontal position or orientation LEFT int Left location or justification NORTH int North (compass) location NORTH_EAST int Northeast (compass) location NORTH_WEST int Northwest (compass) location RIGHT int Right location or justification SOUTH int South (compass) location SOUTH_EAST int Southeast (compass) location SOUTH_WEST int Southwest (compass) location TOP int Top location VERTICAL int Vertical position or orientation WEST int West (compass) location - 917
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.
Posted in Blue | No Comments »
January 26th, 2008
Java Swing - O Reilly Performs a recursive search through the component hierarchy starting at parent, and returns the last component containing the point (x, y). If parent is not a container, it is returned. public static Rectangle getLocalBounds(Component aComponent) Returns a rectangle containing aComponent relative to aComponent, i.e., (0, 0, width, height). public static JRootPane getRootPane(Component c) Finds the root pane containing c. If no JRootPane is found containing c, null is returned. public static void invokeAndWait(Runnable obj) throws InterruptedException, InvocationTargetException public static void invokeLater(Runnable obj) These methods take Runnable arguments and place them on the event queue to be executed after all pending events have been dispatched. The invokeLater() method essentially just pushes this Runnable onto the event queue. The invokeAndWait() method pushes it onto the queue and blocks until it has been dispatched. JComponent is an example of a Swing component that uses this technique of delayed execution. It delays revalidation of any layout components until any other events pending have been handled by calling invokeLater(). Some events rely on the location of their source to function properly (like tooltips), and moving the components before the event has been properly dispatched could cause confusion. As mentioned earlier, Chapter 28 contains a more detailed discussion of these methods. public static boolean isDescendingFrom(Component a, Component b) Returns true if component a descends from b in the component hierarchy. public static boolean isEventDispatchThread() Returns true if the current thread is the event-dispatching thread. public static boolean isLeftMouseButton(MouseEvent anEvent) public static boolean isMiddleMouseButton(MouseEvent anEvent) public static boolean isRightMouseButton(MouseEvent anEvent) These convenience methods return true if anEvent was performed with the left, middle, or right mouse button, respectively. public static final boolean isRectangleContainingRectangle(Rectangle a, Rectangle b) Returns true if rectangle a completely contains rectangle b. public static String layoutCompoundLabel(FontMetrics fm, String text, Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int textIconGap) - 916
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.
Posted in Blue | No Comments »
January 26th, 2008
Java Swing - O Reilly Opposite of the previous method, this method takes a point, p, relative to the upper-left corner of the component, c, and converts it to a coordinate on the screen. Such a conversion makes light work of tiling popup windows. public static Rectangle convertRectangle(Component source, Rectangle aRectangle, Component destination) Translates aRectangle from the source coordinate system to the destination coordinate system, following the same rules as convertPoint(). public static Component findFocusOwner(Component c) Returns the component at or below c that has the keyboard focus, if any. Because of security restrictions, this may not work for non-Swing components in applets. public static Accessible getAccessibleAt(Component c, Point p) Returns the Accessible component at point p (relative to the component c). If no such component exists, null is returned. public static Accessible getAccessibleChild(Component c, int i) Returns the ith accessible child of component c that implements the Accessible interface. public static int getAccessibleChildrenCount(Component c) Returns the number of accessible childern in component c that implements the Accessible interface. public static int getAccessibleIndexInParent(Component c) For a given component c, this method returns its index in its accessible parent. If the component does not have an accessible parent, -1 is returned. public static AccessibleStateSet getAccessibleStateSet(Component c) Returns the set of accessible states active for the component c. public static Container getAncestorNamed(String name, Component comp) Returns the first container named name that contains component comp. null is returned if name cannot be found. public static Container getAncestorOfClass(Class c, Component comp) Similar to getAncestorNamed(), this method returns the first container that is an instance of class c that contains component comp. public static Component getDeepestComponentAt(Component parent, int x, int y) - 915
We recommend high quality webhost to host and run your jsp application: christian web host services.
Posted in Blue | No Comments »
January 25th, 2008
Java Swing - O Reilly Returns the regions in rectA that do not overlap with rectB. If rectA and rectB do not overlap at all, an empty array is returned. The number of rectangles returned depends on the nature of the intersection. public static Rectangle computeIntersection(int x, int y, int width, int height, Rectangle dest) Returns the intersection of two rectangles (the first represented by (x, y, width, height)), without allocating a new rectangle. Instead, dest is modified to contain the intersection and then returned. This can provide a significant performance improvement over the similar methods available directly through the Rectangle class, if you need to do several such intersections. public static int computeStringWidth(FontMetrics fm, String str) Given a particular font metrics, this method returns the pixel length of the string str. public static Rectangle computeUnion(int x, int y, int width, int height, Rectangle dest) Returns the union of the rectangle represented by (x, y, width, height) and dest. As with computeIntersection(), dest is modified and returned; no new Rectangle object is allocated. public static MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination) Returns a new MouseEvent, based on sourceEvent with the (x, y) coordinates translated to destination’s coordinate system and the source of the event set as destination, provided destination is not null. If it is, source is set as the source for the new event. The actual translation of (x, y) is done with convertPoint(). public static Point convertPoint(Component source, Point aPoint, Component destination) public static Point convertPoint(Component source, int x, int y, Component destination) Convert a point from the source coordinate system to the destination coordinate system. If either source or destination is null, the other component’s root component coordinate system will be used. If both are null, the point is returned untranslated. public static void convertPointFromScreen(Point p, Component c) Converts a point on the screen, p, to a coordinate relative to the upper-lefthand corner of the component, c. public static Component getRoot(Component c) Returns the parent Window component, or the last applet to contain c if it is in a browser environment. public static void convertPointToScreen(Point p, Component c) - 914
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.
Posted in Blue | No Comments »
January 25th, 2008
Java Swing - O Reilly We’ve broken these utilities up into several categories, more for presentation than anything. You’ll find the SwingUtilities, SwingConstants, Timer, and ToolTipManager classes in Section 27.1. Section 27.3 covers the KeyStroke and EventListenerList classes. “Editing Utilities” looks at the CellEditor and CellEditorListener interfaces as well as the DefaultCellEditor and KeyStroke classes. And Section 27.4 covers the GrayFilter class. Figure 27.1 shows the classes covered in this chapter: Figure 27.1. Class hierarchy for the utility classes 27.1 General Utilities The general utilities presented here are meant for use with any part of your application. The static methods of the SwingUtilities class are called throughout the Swing source code and will probably be useful to you as well. You’ll find a lot of these utilities fairly straightforward, and maybe even easy to reproduce with your own code. But try to familiarize yourself with these APIs; they’re meant to keep you from reinventing wheels with each new application you write. 27.1.1 The SwingUtilities Class This class serves as a collection point for several methods common in more advanced GUI development projects. You probably won’t use all of the methods in any one application, but some of the methods will doubtless come in handy from time to time. While the purpose of many of these methods will be obvious from their signatures, here’s a brief description of the utility calls at your disposal. If you want to see a more detailed discussion of the invokeLater() and invokeAndWait() methods, check out Chapter 28. 27.1.1.1 Constructor public SwingUtilities() The constructor for SwingUtilities is public, but all of the public methods are static, so you will not need to create an instance. 27.1.1.2 Class Methods public static Rectangle[] computeDifference(Rectangle rectA, Rectangle rectB) - 913
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.
Posted in Blue | No Comments »