1
2 package samplecode;
3
4 import java.awt.*;
5 import java.awt.event.*;
6 import javax.swing.*;
7
8
9
10 /**
11 * <p>Title: Font Names </p>
12 * <p>Description: This program shows how to get the font names </p>
13 * of your OS.
14 * <p>Company: Developer's super Page.com</p>
15 */
16
17
18 public class SampleFrame extends JFrame {
19 JPanel contentPane;
20 BorderLayout borderLayout1 = new BorderLayout();
21 JPanel jpnlMain = new JPanel();
22 JButton jButton1 = new JButton();
23 DefaultListModel model = new DefaultListModel();
24 JLabel jLabel1 = new JLabel();
25
26
27
28 //Construct the frame
29 public SampleFrame() {
30 enableEvents(AWTEvent.WINDOW_EVENT_MASK);
31 try {
32 jbInit();
33 }
34 catch(Exception e) {
35 e.printStackTrace();
36 }
37 }
38
39 //Component initialization
40 private void jbInit() throws Exception {
41 contentPane = (JPanel) this.getContentPane();
42 contentPane.setLayout(borderLayout1);
43 this.setSize(new Dimension(400, 300));
44 this.setTitle("Font Display");
45 this.addHierarchyBoundsListener(new
46 SampleFrame_this_hierarchyBoundsAdapter(this));
47 jpnlMain.setLayout(null);
48 contentPane.setMinimumSize(new Dimension(300, 300));
49 contentPane.setPreferredSize(new Dimension(300, 256));
50 jpnlMain.setDebugGraphicsOptions(0);
51 jpnlMain.setMinimumSize(new Dimension(400, 256));
52 jpnlMain.setPreferredSize(new Dimension(400, 256));
53 jButton1.setBounds(new Rectangle(18, 31, 88, 36));
54 jButton1.setText("Get Fonts");
55 jButton1.addActionListener(new SampleFrame_jButton1_actionAdapter(this));
56
57 contentPane.add(jpnlMain, BorderLayout.CENTER);
58 jpnlMain.add(jButton1, null);
59
60
61 }
62
63 //Overridden so we can exit when window is closed
64 protected void processWindowEvent(WindowEvent e) {
65 super.processWindowEvent(e);
66 if (e.getID() == WindowEvent.WINDOW_CLOSING) {
67 System.exit(0);
68 }
69 }
70
71
72 void jButton1_actionPerformed(ActionEvent e) {
73 /*NOTE if anybody know how to add a scrollbar to a list box
74 please DSP mail me! */
75
76 // Get all font family names
77 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
78
79 //Set the font names to Listbox
80 JList jList1 = new JList(ge.getAvailableFontFamilyNames());
81 jList1.setBounds(new Rectangle(117, 12, 194, 274));
82 jList1.setBorder(BorderFactory.createLineBorder(Color.black));
83
84 //adds List to Panel
85 jpnlMain.add(jList1, null);
86
87 //repaints it to display to user
88 jpnlMain.repaint();
89 }
90
91 }
92
93 class SampleFrame_this_hierarchyBoundsAdapter extends
94 java.awt.event.HierarchyBoundsAdapter {
95 SampleFrame adaptee;
96
97 SampleFrame_this_hierarchyBoundsAdapter(SampleFrame adaptee) {
98 this.adaptee = adaptee;
99 }
100
101 }
102
103 class SampleFrame_jButton1_actionAdapter implements java.awt.event.ActionListener {
104 SampleFrame adaptee;
105
106 SampleFrame_jButton1_actionAdapter(SampleFrame adaptee) {
107 this.adaptee = adaptee;
108 }
109 public void actionPerformed(ActionEvent e) {
110 adaptee.jButton1_actionPerformed(e);
111 }
112 }
|