01: /**
02: * L2FProd.com Common Components 7.3 License.
03: *
04: * Copyright 2005-2007 L2FProd.com
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package com.l2fprod.common.demo;
18:
19: import com.l2fprod.common.swing.JFontChooser;
20: import com.l2fprod.common.swing.PercentLayout;
21:
22: import java.awt.Component;
23: import java.awt.Font;
24: import java.awt.event.ActionEvent;
25: import java.awt.event.ActionListener;
26:
27: import javax.swing.JButton;
28: import javax.swing.JOptionPane;
29: import javax.swing.JPanel;
30: import javax.swing.UIManager;
31:
32: /**
33: * A simple example showing how to use the JFontChooser.
34: */
35: public class ChooseFont extends JPanel {
36:
37: public ChooseFont() {
38: setLayout(new PercentLayout(PercentLayout.VERTICAL, 3));
39:
40: JFontChooser chooser = new JFontChooser();
41: chooser.setSelectedFont(new Font("Dialog", Font.BOLD
42: | Font.ITALIC, 56));
43: add("*", chooser);
44:
45: JButton button = new JButton("Click here to show JFontChooser");
46: button.addActionListener(new ActionListener() {
47: public void actionPerformed(ActionEvent e) {
48: selectFont(ChooseFont.this );
49: }
50: });
51: add(button);
52: }
53:
54: private static void selectFont(Component parent) {
55: Font selectedFont = JFontChooser.showDialog(parent,
56: "Choose Font", null);
57: if (selectedFont == null) {
58: JOptionPane.showMessageDialog(parent,
59: "You clicked 'Cancel'");
60: } else {
61: JOptionPane.showMessageDialog(parent, "You selected '"
62: + selectedFont.getName() + "'");
63: }
64: }
65:
66: public static void main(String[] args) throws Exception {
67: UIManager.setLookAndFeel(UIManager
68: .getSystemLookAndFeelClassName());
69: selectFont(null);
70: System.exit(0);
71: }
72:
73: }
|