Web hosting reviews - Java Swing O Reilly component with multiple borders
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 -
Note: If you are looking for cheap webhost to host and run your apache application check Vision jboss web hosting services