CIB jrec technischer Leitfaden
6. Einbindung des CIB jrec in Java
6.1. Einbindung in eine Java Swing-Applikation
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import de.cib.jrec.JCibRec;
public class MyRecTest extends JFrame {
private static final long serialVersionUID = 1L;
public static final String TEST_FILENAME = "c://tmp//rtf_data.rtf";
JCibRec m_cibRec;
public MySwingRecTest() {
m_cibRec = new JCibRec();
JPanel recPanel = new JPanel();
recPanel.add(m_cibRec);
getContentPane().add(recPanel);
m_cibRec.setPreferredSize(new Dimension(650, 200));
// set standard formatting
initDocumentAttributes();
// set input file (optional)
m_cibRec.setProperty(ICibApplication.PROPERTY_INPUTFILE, TEST_FILENAME);
// set Jrec application title
m_cibRec.setProperty(ICibApplication.PROPERTY_TITLE, "CIB JRec integriert in Swing");
// disable jrec menu bar – must be done
// if custom application uses its own menu bar // if custom application uses its own menu bar
m_cibRec.setProperty(ICibApplication.PROPERTY_MENU_ENABLED, Boolean.FALSE);
// set other Properties
//...
// jrec start and load
m_cibRec.start();
m_cibRec.load();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setLocation(200, 50);
setResizable(false);
pack();
}
// set standard formatting
private void initDocumentAttributes() {
MutableAttributeSet defaultAttributes =
new SimpleAttributeSet();
StyleConstants.setFontSize(defaultAttributes, 8);
StyleConstants.setFontFamily(defaultAttributes, "Courier New");
m_cibRec.getRecRichEditPane().setDocumentAttributeDefaults(
defaultAttributes);
}
public static void main(String[] args)
{
MySwingRecTest recTest = new MySwingRecTest();
recTest.setVisible(true);
}
}
Die Funktion initDocumentAttributes() zeigt beispielhaft, wie Sie die standardmäßige Schriftart und Schriftgröße für das Dokument setzen können.