Code example for JTextComponent

Methods: setCaretPosition

        final JTextComponent c = getComponent();
        // apparently, focus has already been granted by the time this mouse listener fires 
    //    if (c.hasFocus()) return; 
        c.setCaretPosition(viewToModel(c, e.getPoint()));
    public void mouseEntered(final MouseEvent e) { } 
    public void mouseExited(final MouseEvent e) { } 
    public void mousePressed(final MouseEvent e) { } 
    public void mouseReleased(final MouseEvent e) { } 
Experience pair programming with AI  Get Codota for Java