Java Reference
In-Depth Information
/** The font name chooser */
protected
protected JList fontNameChoice ;
/** The font size chooser */
protected
protected JList fontSizeChoice ;
/** The bold and italic choosers */
JCheckBox bold , italic ;
/** The list of font sizes */
protected
protected Integer fontSizes [] = {
8 , 9 , 10 , 11 , 12 , 14 , 16 , 18 , 20 , 24 , 30 , 36 , 40 , 48 , 60 , 72
};
/** The index of the default size (e.g., 14 point == 4) */
protected
protected static
int DEFAULT_SIZE = 4 ;
/** The font display area.
*/
protected
static final
final int
protected JLabel previewArea ;
/** Construct a FontChooser -- Sets title and gets
* array of fonts on the system. Builds a GUI to let
* the user choose one font at one size.
*/
public
public FontChooser ( JFrame f ) {
super
super ( f , "Font Chooser" , true
true );
Container cp = getContentPane ();
JPanel top = new
new JPanel ();
top . setBorder ( new
new TitledBorder ( new
new EtchedBorder (), "Font" ));
top . setLayout ( new
new FlowLayout ());
// This gives a longish list; most of the names that come
// with your OS (e.g., Helvetica, Times), plus the Sun/Java ones (Lucida,
// Lucida Bright, Lucida Sans...)
String [] fontList = GraphicsEnvironment . getLocalGraphicsEnvironment ().
getAvailableFontFamilyNames ();
fontNameChoice = new
new JList ( fontList );
top . add ( new
new JScrollPane ( fontNameChoice ));
fontNameChoice . setVisibleRowCount ( fontSizes . length );
fontNameChoice . setSelectedValue ( "Serif" , true
true );
fontSizeChoice = new
new JList ( fontSizes );
top . add ( fontSizeChoice );
fontSizeChoice . setSelectedIndex ( fontSizes . length * 3 / 4 );
Search WWH ::




Custom Search