Java Reference
In-Depth Information
areavailablepriortocalling pack() ,andchangingthemaftercalling pack() would
require another call to pack() to ensure that the GUI is properly sized.
Compile Listing 7-6 and run this application. Figure 7-13 shows the resulting GUI.
Figure 7-13. A tooltip appears when you move the mouse cursor over a textfield.
Note TempVerter demonstrates some of Swing's many components, which are
located in the javax.swing package. Other components that you'll find useful in-
clude JScrollPane (Swing'sversionof ScrollPane ), JTextArea (Swing'sver-
sion of TextArea ), and JOptionPane (a class that makes it easy to pop up a
standard dialog box that prompts users for a value or informs them of something).
JOptionPane declares showConfirmDialog() , showInputDialog() ,
showMessageDialog() ,and showOptionDialog() classmethodstoaskcon-
firmingquestions(yes/no/cancel),promptforinput,telltheuseraboutsomethingthat
has happened, and combine confirmation with input and message display.
TempVerter Meets JLayer
Suppose you plan to distribute your Swing application as shareware (see ht-
tp://en.wikipedia.org/wiki/Shareware ) andwanttodisplayatranslucent
UNREGISTEREDmessageovertheGUIuntiltheuserregisterstheircopy.Youcould
accomplishthistaskbyworkingwiththeglasspanedirectly,oryoucouldworkwiththe
javax.swing.JLayer class, which is new in Java 7.
JLayer 'sJavadocdescribesthisclassas“auniversaldecoratorforSwingcompon-
ents, which enables you to implement various advanced painting effects as well as re-
ceive notifications of all AWTEvent s generated within its borders.” JLayer works
with a glass pane on your behalf.
Search WWH ::




Custom Search