-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
PanelExample.java
39 lines (32 loc) · 1.42 KB
/
PanelExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.awt.BorderLayout;
import java.lang.reflect.InvocationTargetException;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import org.drjekyll.fontchooser.FontChooser;
import org.drjekyll.fontchooser.model.FontSelectionModel;
public class PanelExample implements Runnable {
private final JLabel selection = new JLabel("Selected font will be displayed here");
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
ExampleRunner.useLookAndFeel(UIManager.getSystemLookAndFeelClassName());
ExampleRunner.invoke(new PanelExample());
}
@Override
public void run() {
selection.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
FontChooser fontChooser = new FontChooser();
fontChooser.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
fontChooser.addChangeListener(event -> {
FontSelectionModel model = (FontSelectionModel) event.getSource();
selection.setText(model.getSelectedFont().toString());
});
JFrame frame = new JFrame("Select Font");
frame.setSize(600, 400);
frame.add(fontChooser);
frame.add(selection, BorderLayout.PAGE_END);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
}