Я получаю эту случайную ошибку Jni, иногда коды работают, иногда нет
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
public class Fonts {
public static void main(String[] args) {
Fonts fs = new Fonts();
try {
fs.initialize();
} catch (Exception e) {
e.printStackTrace();
}
fs.frm.setVisible(true);
}
private String[] fnt;
private JFrame frm;
private JScrollPane jsp;
private JTextPane jta;
private int width = 450;
private int height = 300;
private GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
private Font[] fnts;
private StyledDocument doc;
private MutableAttributeSet mas;
// private String[] fams;
private int cp = 0;
public Fonts() {
}
public void dis(String s) {
try {
doc.insertString(cp, s, mas);
doc.insertString(cp, "\n", mas);
} catch (Exception e) {
e.printStackTrace();
}
}
public void initialize() throws BadLocationException {
frm = new JFrame("awesome");
frm.setMinimumSize(new Dimension(width, height));
frm.setBounds(100, 100, width, height);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.getContentPane().setLayout(new BorderLayout());
fnts = ge.getAllFonts();
jta = new JTextPane();
doc = jta.getStyledDocument();
jsp = new JScrollPane(jta);
frm.getContentPane().add(jsp, BorderLayout.CENTER);
frm.pack();
fnt = ge.getAvailableFontFamilyNames();
mas = jta.getInputAttributes();
for (int i = 0; i < fnt.length; i++) {
StyleConstants.setBold(mas, false);
StyleConstants.setItalic(mas, false);
StyleConstants.setFontFamily(mas, fnt[i]);
StyleConstants.setFontSize(mas, 16);
dis(fnt[i]);
StyleConstants.setBold(mas, true);
dis(fnt[i] + " Bold");
StyleConstants.setItalic(mas, true);
dis(fnt[i] + " Bold & Italic");
StyleConstants.setBold(mas, false);
dis(fnt[i] + " Italic");
}
}
}
И вот ошибка, которую я получаю.