Java Reference
In-Depth Information
Rectangle bounds = getBounds();
fontDlg.setLocationRelativeTo(this);
fontDlg.setVisible(true);
// Show the
dialog
}
}
Directory "Sketcher 5 displaying a font dialog"
The new else if block makes the dialog visible after setting its location in relation to the application
window. Calling the setLocationRelativeTo() method that is inherited from the Window class in
JDialog makes the center of the dialog coincide with the center of the component passed as the argu-
ment, which in this case is the application window. If you want to position it differently, you could call
the setLocation() method with specific coordinates for where you want the top-left corner of the dia-
log to be.
If you recompile Sketcher, you are able to play with fonts to your heart's content. Figure 20-11 shows
what I mean.
FIGURE 20-11
 
 
Search WWH ::




Custom Search