Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

Java Source Code


You're Browsing As A Guest! Register Now...
Become a Java Expert!

Join 358,291 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,464 people online right now.Registration is fast and FREE... Join Now!




Accommodating Fonts in a single window

This snippet shows you all how to accommodate all the available fonts on your computer in a single window. I have taken for instance, 634 fonts.

Submitted By: rishabhsharma
Actions:
Rating:
Views: 179

Language: Java

Last Modified: April 24, 2009

Snippet


  1. import java.awt.*; //import some necessary package stuffs.
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import java.applet.*;
  5. class AccommodatingFonts extends JFrame //extends JFrame to form main window
  6.     {
  7.        AccommodatingFonts() //constructor
  8.             {   
  9.                 setTitle("Available Fonts"); //setting title of the main window
  10.                 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();//getting reference to the available fonts
  11.                 Fonts = ge.getAvailableFontFamilyNames(); //getting available fonts
  12.                 setSize(400,400); //size of the main window
  13.                 fonts = new JList(Fonts); //JList to accommodate all the fonts
  14.                 fonts.setVisibleRowCount(100); //sets 100 fonts in a single vertical column
  15.                 JScrollPane pane = new JScrollPane(fonts); //add scrollPane to scroll the panel
  16.                 fonts.setLayoutOrientation(JList.VERTICAL_WRAP); //it wrap all the fonts vertically so as to divide th
  17.                                               //the fonts if could not be accommodated in a single vertical column i.e. after 100
  18.                 add(pane); //adding scrollpane to the main window
  19.             }
  20.         String[] Fonts; //array to contain list of fonts
  21.         JList fonts;
  22.         public static void main(String[] args)
  23.             {
  24.                 new AccommodatingFonts().setVisible(true); //setting the main window visibility to true
  25.             }
  26.         }
  27.  
  28.  

Copy & Paste


Comments

There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month