Example usage for javax.swing.text NavigationFilter NavigationFilter

List of usage examples for javax.swing.text NavigationFilter NavigationFilter

Introduction

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

Prototype

NavigationFilter

Source Link

Usage

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Navigation Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextArea textArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(textArea);
    frame.add(scrollPane, BorderLayout.CENTER);

    NavigationFilter filter = new NavigationFilter() {
        public void setDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias) {
            System.out.println("Setting: " + dot);
            fb.setDot(dot, bias);// w ww. ja  v a2s  .co  m

        }

        public void moveDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias) {
            System.out.println("Moving: " + dot);
            fb.setDot(dot, bias);
        }
    };

    textArea.setNavigationFilter(filter);

    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    final String START_STRING = "Start\n";
    final int START_STRING_LENGTH = START_STRING.length();

    JFrame frame = new JFrame("Navigation Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextArea textArea = new JTextArea(START_STRING);
    textArea.setCaretPosition(START_STRING_LENGTH);
    JScrollPane scrollPane = new JScrollPane(textArea);
    frame.add(scrollPane, BorderLayout.CENTER);

    NavigationFilter filter = new NavigationFilter() {
        public void setDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias) {
            if (dot < START_STRING_LENGTH) {
                fb.setDot(START_STRING_LENGTH, bias);
            } else {
                fb.setDot(dot, bias);/* ww  w.  j  av  a  2  s  .  c  o m*/
            }
        }

        public void moveDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias) {
            if (dot < START_STRING_LENGTH) {
                fb.setDot(START_STRING_LENGTH, bias);
            } else {
                fb.setDot(dot, bias);
            }
        }
    };

    textArea.setNavigationFilter(filter);

    frame.setSize(250, 150);
    frame.setVisible(true);
}