JTextField: setNavigationFilter(NavigationFilter filter) : JTextField « javax.swing « Java by API






JTextField: setNavigationFilter(NavigationFilter filter)

 

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.text.NavigationFilter;
import javax.swing.text.Position;

public class MainClass {
  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);
        }
      }

      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);
  }
}

           
         
  








Related examples in the same category

1.JTextField.LEFT
2.JTextField.LEADING
3.JTextField.TRAILING
4.new JTextField(String text)
5.new JTextField(String text, int columns)
6.JTextField: addActionListener(ActionListener s)
7.JTextField: addFocusListener(FocusListener l)
8.JTextField: addKeyListener(KeyListener l)
9.JTextField: copy()
10.JTextField: cut()
11.JTextField: getActions()
12.JTextField: getCaretPosition()
13.JTextField: getDocument()
14.JTextField: getHorizontalVisibility()
15.JTextField: getHorizontalVisibility() (2)
16.JTextField: getInputMap()
17.JTextField: getKeymap()
18.JTextField: getScrollOffset()
19.JTextField: paste()
20.JTextField: registerKeyboardAction(ActionListener anAction,String aCommand,KeyStroke aKeyStroke,int aCondition)
21.JTextField: requestFocus()
22.JTextField: modelToView(int pos)
23.JTextField: read(Reader in, Object desc)
24.JTextField: setDocument(Document doc)
25.JTextField: setFocusAccelerator(char aKey)
26.JTextField: setHorizontalAlignment(int alignment)
27.JTextField: setInputVerifier(InputVerifier input)
28.JTextField: setPreferredSize(Dimension preferredSize)
29.JTextField: setTransferHandler(TransferHandler newHandler)
30.JTextField: write(Writer out)