1 16 17 package org.mc4j.console.swing.editor.xml; 18 19 23 24 import javax.swing.*; 25 import javax.swing.text.StyledEditorKit ; 26 import java.awt.*; 27 import java.io.File ; 28 import java.io.FileReader ; 29 import java.io.IOException ; 30 31 public class JEditorTest extends JPanel { 32 33 public JEditorTest(File file) 34 throws IOException { 35 StyledEditorKit kit = null; 37 if (file.getName().toLowerCase().endsWith(".xml")) { 38 kit = new XMLStyleTokens.Kit(); 39 } 40 41 JEditorPane editor = new JEditorPane(); 42 editor.setEditorKit(kit); 43 editor.read(new FileReader (file), null); 44 45 ((EditorDocument)editor.getDocument()).setValidating(true); 46 47 setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); 48 setLayout(new GridLayout()); 49 add(new JScrollPane(editor)); 50 } 51 52 public static void main(String [] args) 53 throws IOException { 54 File file = new File ("org/mc4j/console/swing/editor/xml/BasicMBean.xml"); 55 JFrame frame = new JFrame("JEditor Test"); 56 frame.getContentPane().setLayout(new BorderLayout()); 57 frame.getContentPane().add(new JEditorTest(file),BorderLayout.CENTER); 58 frame.setSize(700, 550); 59 frame.setVisible(true); 60 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 61 } 62 } 63 | Popular Tags |