Skip to content

Instantly share code, notes, and snippets.

@halirutan
Created October 26, 2017 12:34
Show Gist options
  • Save halirutan/875bb442ed1fffb3a12c9b5ed63561a6 to your computer and use it in GitHub Desktop.
Save halirutan/875bb442ed1fffb3a12c9b5ed63561a6 to your computer and use it in GitHub Desktop.
package org.jabref;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import org.jabref.model.strings.LatexToUnicodeAdapter;
public class SwingJLabelTester extends JPanel{
private SwingJLabelTester() {
super(new GridLayout(3,1)); //3 rows, 1 column
final String latexString = LatexToUnicodeAdapter.format("This is a \\textit{test for italics} and \\textbf{a test for bold}");
final JLabel label = new JLabel(latexString, SwingConstants.CENTER);
label.setVerticalTextPosition(SwingConstants.BOTTOM);
label.setHorizontalTextPosition(SwingConstants.CENTER);
add(label);
}
private static void createAndShowGUI() {
final JFrame frame = new JFrame("LabelDemo");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(new SwingJLabelTester());
frame.setSize(400,400);
frame.setVisible(true);
}
public static void main(final String[] args) {
SwingUtilities.invokeLater(SwingJLabelTester::createAndShowGUI);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment