I get this Random Jni error, sometimes the codes works, sometimes it doesn’t
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");
}
}
}
And here is the error I get.
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0xb3fdad10, pid=20482, tid=3066784624
#
# JRE version: 6.0_26-b03
# Java VM: Java HotSpot(TM) Client VM (20.1-b02 mixed mode, sharing linux-x86 )
# Problematic frame:
# C [libfontmanager.so+0x2ed10] float+0x40
#
# An error report file with more information is saved as:
# /home/alex/repos/java-alex.fonts/bin/hs_err_pid20482.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Aborted
added importans / standard Swing rulles
changed main method
moved all methods for JFrame from the toop to the end of methods,
set
PrefferedSizeto theJScrollPanethen for example
Fontto theJTextPane, there are wrong order fromZ - > A(just my helicopter view)EDIT: and changed access/visibily (@ by attn trashgod)
from
to