Package javax.swing.text

Examples of javax.swing.text.JTextComponent.select()


    } else {
      offset = bias == null || bias == Position.Bias.Forward ? 0 : textComp
          .getDocument().getLength();
      index = getNextMatch(textComp, str, offset, bias);
      if (index != -1) {
        textComp.select(index, index + str.length());
        return true;
      } else {
        return false;
      }
    }
View Full Code Here


    public void keyPressed(KeyEvent e) {
      if ((toSetIn != null) && (e.getKeyCode() == KeyEvent.VK_ENTER)) {
            JTextComponent comp = (JTextComponent) e.getSource();
            int end = comp.getSelectionEnd();
            comp.select(end, end);
            e.consume();
            return;
        }
        // Cycle through alternative completions when user presses PGUP/PGDN:
        else if ((e.getKeyCode() == KeyEvent.VK_PAGE_DOWN) && (lastCompletions != null)) {
View Full Code Here

                toSetIn = toSetIn.substring(1);
                if (toSetIn.length() > 0) {
                    int cp = comp.getCaretPosition();
                    //comp.setCaretPosition(cp+1-toSetIn.);
                    //System.out.println(cp-toSetIn.length()+" - "+cp);
                    comp.select(cp + 1 - toSetIn.length(), cp);
                    lastBeginning = lastBeginning + ch;

                    e.consume();
                    lastCaretPosition = comp.getCaretPosition();
View Full Code Here

                    String text = comp.getText();
                    //Util.pr(""+lastLen);
                    comp.setText(text.substring(0, lastCaretPosition - lastLen)
                            + toSetIn
                            + text.substring(lastCaretPosition));
                    comp.select(lastCaretPosition + 1 - lastLen,
                            lastCaretPosition + toSetIn.length() - lastLen);

                    lastCaretPosition = comp.getCaretPosition();
                    e.consume();
                    return;
View Full Code Here

                int cp = comp.getCaretPosition();
                alltext.insert(cp, toSetIn);
                //Util.pr(alltext.toString());
                comp.setText(alltext.toString());
                comp.setCaretPosition(cp);
                comp.select(cp + 1, cp + 1 + sno.length() - currentword.length());
                e.consume();
                lastCaretPosition = comp.getCaretPosition();
                lastBeginning = currentword.toString();
                return;
            }
View Full Code Here

                    JTextComponent text = (JTextComponent) e.getSource();
                    text.selectAll();
                }
                public void focusLost(FocusEvent e) {
                    JTextComponent text = (JTextComponent) e.getSource();
                    text.select(0, 0);
                }
            }
        );
        text.setInputVerifier(
            new InputVerifier() {
View Full Code Here

    // this depends on who has the focus right now.
    final Component owner = FocusManager.getCurrentManager().getPermanentFocusOwner();
    if (owner instanceof JTextComponent)
    {
      final JTextComponent textComponent = (JTextComponent) owner;
      textComponent.select(textComponent.getCaretPosition(), textComponent.getCaretPosition());
    }
    else if (owner instanceof TextComponent)
    {
      final TextComponent textComponent = (TextComponent) owner;
      textComponent.select(textComponent.getCaretPosition(), textComponent.getCaretPosition());
View Full Code Here

      textComponent.select(textComponent.getCaretPosition(), textComponent.getCaretPosition());
    }
    else if (owner instanceof TextComponent)
    {
      final TextComponent textComponent = (TextComponent) owner;
      textComponent.select(textComponent.getCaretPosition(), textComponent.getCaretPosition());
    }
    else if (owner instanceof JTable)
    {
      final JTable table = (JTable) owner;
      table.clearSelection();
View Full Code Here

        String findText = txtFind.getText().toLowerCase();
        String txt = txtComp.getText().toLowerCase();
        int startPos = txt.indexOf(findText, txtComp.getCaretPosition());
        int length = findText.length();
        if (startPos > -1) {
            txtComp.select(startPos,startPos+length);
            txtComp.requestFocus();
                txtFind.requestFocus();
        } else {
            Toolkit.getDefaultToolkit().beep();
        }
View Full Code Here

            //We need it because TextComponent clears selection by focus gain event.
            if (needToRestoreSelection) {
        final JTextComponent textComponent = (JTextComponent) lastFocusOwner;
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            textComponent.select(selectionStart[0], selectionEnd[0]);
          }
        });
      }
        }
        /*
 
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.