fontchooser-example.2.4.source-code.ShowDialogExample Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fontchooser-example Show documentation
Show all versions of fontchooser-example Show documentation
Example on how to use the Java Swing Font Chooser component
The newest version!
import org.drjekyll.fontchooser.FontDialog;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
import javax.swing.plaf.metal.MetalLookAndFeel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.reflect.InvocationTargetException;
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);
}
}