List of usage examples for javax.swing JTextArea getDocument
public Document getDocument()
From source file:ListenerSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Offset Example"); Container content = frame.getContentPane(); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); final Document document = textArea.getDocument(); document.addDocumentListener(new MyListener()); content.add(scrollPane, BorderLayout.CENTER); frame.setSize(250, 150);/*from w w w. ja v a2 s. c om*/ frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Undo Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); UndoManager manager = new UndoManager(); textArea.getDocument().addUndoableEditListener(manager); JToolBar toolbar = new JToolBar(); JButton undoButton = new JButton( new UndoAction(manager, (String) UIManager.get("AbstractUndoableEdit.undoText"))); toolbar.add(undoButton);/*from ww w . j a va 2s . c o m*/ Container content = frame.getContentPane(); content.add(toolbar, BorderLayout.NORTH); content.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:TextAreaElements.java
public static void main(String[] args) { try {/*from w w w. j av a2 s . c o m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Text Area Elements"); JTextArea ta = new JTextArea(5, 32); ta.setText("That's one small step for man...\nOne giant leap for mankind."); f.getContentPane().add(ta); f.pack(); f.setVisible(true); ((AbstractDocument) ta.getDocument()).dump(System.out); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Undo Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); UndoManager manager = new UndoManager(); textArea.getDocument().addUndoableEditListener(manager); JToolBar toolbar = new JToolBar(); JButton undoButton = new JButton( new UndoAction(manager, (String) UIManager.get("AbstractUndoableEdit.undoText"))); toolbar.add(undoButton);/*from w ww .j av a 2 s. co m*/ JButton redoButton = new JButton( new RedoAction(manager, (String) UIManager.get("AbstractUndoableEdit.redoText"))); toolbar.add(redoButton); Container content = frame.getContentPane(); content.add(toolbar, BorderLayout.NORTH); content.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:UndoManagerHelper.java
public static void main(String args[]) { JFrame frame = new JFrame("Undo Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); UndoManager manager = new UndoManager(); textArea.getDocument().addUndoableEditListener(manager); JToolBar toolbar = new JToolBar(); JButton undoButton = new JButton(UndoManagerHelper.getUndoAction(manager)); toolbar.add(undoButton);/*from w w w . j a va 2s . c om*/ JButton redoButton = new JButton(UndoManagerHelper.getRedoAction(manager)); toolbar.add(redoButton); frame.add(toolbar, BorderLayout.NORTH); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); JTextArea ta = new JTextArea(5, 32); ta.setText("That's one small step for man...\nOne giant leap for mankind."); ta.setLineWrap(true);/*from w w w . j av a 2 s .c o m*/ ta.setWrapStyleWord(true); f.getContentPane().add(ta); f.setSize(100, 100); f.setVisible(true); ((AbstractDocument) ta.getDocument()).dump(System.out); }
From source file:ElementSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Element Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); JButton button = new JButton("Show Elements"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Document document = textArea.getDocument(); ElementIterator iterator = new ElementIterator(document); Element element = iterator.first(); while (element != null) { System.out.println(element.getStartOffset()); element = iterator.next(); }/*from w w w . j a va 2s . co m*/ } }; button.addActionListener(actionListener); frame.add(scrollPane, BorderLayout.CENTER); frame.add(button, BorderLayout.SOUTH); frame.setSize(250, 250); frame.setVisible(true); }
From source file:ElementSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Element Example"); Container content = frame.getContentPane(); final JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); JButton button = new JButton("Show Elements"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Document document = textArea.getDocument(); ElementIterator iterator = new ElementIterator(document); Element element = iterator.first(); while (element != null) { System.out.println(element.getStartOffset()); element = iterator.next(); }// w ww . j a v a2 s. c om } }; button.addActionListener(actionListener); content.add(scrollPane, BorderLayout.CENTER); content.add(button, BorderLayout.SOUTH); frame.setSize(250, 250); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Element Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); JButton button = new JButton("Show Elements"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Document document = textArea.getDocument(); ElementIterator iterator = new ElementIterator(document); Element element = iterator.first(); while (element != null) { System.out.println(element.getStartOffset()); element = iterator.next(); }/*from ww w . ja va 2 s.c o m*/ } }; button.addActionListener(actionListener); frame.add(scrollPane, BorderLayout.CENTER); frame.add(button, BorderLayout.SOUTH); frame.setSize(250, 250); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel topPanel = new JPanel(); topPanel.setPreferredSize(new Dimension(200, 200)); topPanel.setBackground(Color.WHITE); JTextArea chatArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(chatArea); JPanel mainPanel = new JPanel(new BorderLayout(5, 5)); mainPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); mainPanel.add(topPanel, BorderLayout.CENTER); mainPanel.add(scrollPane, BorderLayout.SOUTH); chatArea.getDocument().addDocumentListener(new DocumentListener() { @Override//from w w w . j av a 2 s . co m public void insertUpdate(DocumentEvent e) { updateLineCount(); } @Override public void removeUpdate(DocumentEvent e) { updateLineCount(); } @Override public void changedUpdate(DocumentEvent e) { updateLineCount(); } private void updateLineCount() { int lineCount = chatArea.getLineCount(); if (lineCount <= 4) { chatArea.setRows(lineCount); mainPanel.revalidate(); } } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(mainPanel); f.pack(); f.setVisible(true); }