Example usage for javax.swing.text ElementIterator first

List of usage examples for javax.swing.text ElementIterator first

Introduction

In this page you can find the example usage for javax.swing.text ElementIterator first.

Prototype

public Element first() 

Source Link

Document

Fetches the first element.

Usage

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   www .ja v a  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();
            }//from w  w  w  .j a v  a 2 s.c o m
        }
    };
    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  w ww .  ja v a 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:LiveParenMatcher.java

public void removeUpdate_2(DocumentEvent de) {
    // print some debugging information before matching the parens
    ElementIterator iter = new ElementIterator(de.getDocument());

    for (Element elem = iter.first(); elem != null; elem = iter.next()) {
        DocumentEvent.ElementChange change = de.getChange(elem);
        if (change != null) { // null means there was no change in elem
            System.out.println("Element " + elem.getName() + " (depth " + iter.depth()
                    + ") changed its children: " + change.getChildrenRemoved().length + " children removed, "
                    + change.getChildrenAdded().length + " children added.\n");
        }/* w  w w  . j  a v  a 2 s.  c o m*/
    }
    SwingUtilities.invokeLater(this); // will call run()
}