Example usage for javax.swing JTextField viewToModel

List of usage examples for javax.swing JTextField viewToModel

Introduction

In this page you can find the example usage for javax.swing JTextField viewToModel.

Prototype

@Deprecated(since = "9")
public int viewToModel(Point pt) 

Source Link

Document

Converts the given place in the view coordinate system to the nearest representative location in the model.

Usage

From source file:org.yccheok.jstock.gui.NewBuyTransactionJDialog.java

private MouseListener getJFormattedTextFieldMouseListener() {
    MouseListener ml = new MouseAdapter() {
        @Override//w  w  w  .jav  a2s .com
        public void mousePressed(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                // Ignore double click.
                return;
            }

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    JTextField tf = (JTextField) e.getSource();
                    int offset = tf.viewToModel(e.getPoint());
                    tf.setCaretPosition(offset);
                }
            });
        }
    };
    return ml;
}