-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ShowDialogExample.java
44 lines (35 loc) · 1.36 KB
/
ShowDialogExample.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
40
41
42
43
44
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
import javax.swing.plaf.metal.MetalLookAndFeel;
import org.drjekyll.fontchooser.FontDialog;
public class ShowDialogExample implements Runnable {
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
ExampleRunner.useLookAndFeel(MetalLookAndFeel.class);
ExampleRunner.invoke(new ShowDialogExample());
}
@Override
public void run() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(600, 300);
JTextArea textArea = new JTextArea("This text will be formatted according to the selected font. " +
"Double click to change font.");
textArea.setLineWrap(true);
textArea.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
FontDialog.showDialog(textArea);
}
}
});
JScrollPane scrollPane = new JScrollPane(textArea);
frame.add(scrollPane);
frame.setVisible(true);
}
}