List of usage examples for javax.swing.text JTextComponent setDocument
@BeanProperty(expert = true, description = "the text document model") public void setDocument(Document doc)
From source file:Main.java
public static void main(String[] argv) { JTextComponent textComp1 = new JTextArea(); JTextComponent textComp2 = new JTextArea(); textComp2.setDocument(textComp1.getDocument()); }
From source file:Main.java
public static void main(String[] argv) { JTextComponent textComp = new JTextField(); textComp.setDocument(new FixedSizePlainDocument(10)); }
From source file:LoadSync.java
public static void doLoadCommand(JTextComponent textComponent, String filename) { FileReader reader = null;/*from ww w .ja v a2 s .com*/ try { System.out.println("Loading"); reader = new FileReader(filename); // Create empty HTMLDocument to read into HTMLEditorKit htmlKit = new HTMLEditorKit(); HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument(); // Create parser (javax.swing.text.html.parser.ParserDelegator) HTMLEditorKit.Parser parser = new ParserDelegator(); // Get parser callback from document HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0); // Load it (true means to ignore character set) parser.parse(reader, callback, true); // Replace document textComponent.setDocument(htmlDoc); System.out.println("Loaded"); } catch (IOException exception) { System.out.println("Load oops"); exception.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException ignoredException) { } } } }