Skip to content

Instantly share code, notes, and snippets.

@erictroebs
Last active June 21, 2021 17:48
Show Gist options
  • Save erictroebs/6580036cf3b0335437b4bff7f26e70b8 to your computer and use it in GitHub Desktop.
Save erictroebs/6580036cf3b0335437b4bff7f26e70b8 to your computer and use it in GitHub Desktop.
comparison between default and monospaced font in Java Swing
import javax.swing.*;
import java.awt.*;
public class SetFontMonospaced {
public static final String TEXT = " A C G T\nA * - - -\nC - * - -\nG - - * -\nT - - - *";
public static void main(String[] args) {
for (int i = 1; i <= 2; i++) {
JFrame frame = new JFrame("Fenster " + i);
frame.setSize(640, 360);
JTextPane textPane = new JTextPane();
textPane.setText(TEXT);
if (i == 2) {
textPane.setFont(Font.getFont(Font.MONOSPACED));
}
frame.add(textPane);
frame.setVisible(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment