Java Code Examples for javax.swing.JTextArea.getCaretPosition()

The following are Jave code examples for showing how to use getCaretPosition() of the javax.swing.JTextArea class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: EditCalculateAndChart   File: FindRight_Action.java   Source Code and License Vote up 6 votes
@Override
public void actionPerformed(ActionEvent e) {
     JTextArea area = TEdit.getTextArea();
     String txt = area.getText();
     if(txt == null)
         return;
     String s = TEdit.getLookingFor();
     if(s.contentEquals(""))
         return;
     if(txt.contentEquals("") || txt.length()<1)
         return;
      if(area.getCaretPosition() >=txt.length()-1){
          area.setCaretPosition(0);
          //JOptionPane.showMessageDialog(TEdit.getFrame(),"Reached the end of the text");
          //return;
      }
           int foundAt = txt.indexOf(s,area.getCaretPosition()+s.length());
           if(foundAt == -1){
               JOptionPane.showMessageDialog(TEdit.getFrame(),"Reached the end of the text");
               return;
           }
               area.setCaretPosition(foundAt);
               area.select(foundAt,foundAt+s.length());
}
 
Example 2
Project: incubator-netbeans   File: TaskPanel.java   Source Code and License Vote up 5 votes
private void makeCaretVisible (JTextArea textArea) {
    int pos = textArea.getCaretPosition();
    try {
        Rectangle rec = textArea.getUI().modelToView(textArea, pos);
        if (rec != null) {
            Point p = SwingUtilities.convertPoint(textArea, rec.x, rec.y, this);
            scrollRectToVisible(new Rectangle(p.x, p.y, rec.width, rec.height));
        }
    } catch (BadLocationException blex) {
        LOG.log(Level.INFO, blex.getMessage(), blex);
    }
}
 
Example 3
Project: incubator-netbeans   File: IssuePanel.java   Source Code and License Vote up 5 votes
void makeCaretVisible(JTextArea textArea) {
    int pos = textArea.getCaretPosition();
    try {
        Rectangle rec = textArea.getUI().modelToView(textArea, pos);
        if (rec != null) {
            Point p = SwingUtilities.convertPoint(textArea, rec.x, rec.y, this);
            scrollRectToVisible(new Rectangle(p.x, p.y, rec.width, rec.height));
        }
    } catch (BadLocationException blex) {
        Bugzilla.LOG.log(Level.INFO, blex.getMessage(), blex);
    }
}
 
Example 4
Project: EditCalculateAndChart   File: FindLeft_Action.java   Source Code and License Vote up 5 votes
@Override
public void actionPerformed(ActionEvent e) {
     JTextArea area = TEdit.getTextArea();
     String txt = area.getText();
     if(txt == null)
         return;
     String s = TEdit.getLookingFor();
     if(s.contentEquals(""))
         return;
     if(txt.contentEquals("") || txt.length()<1)
         return;
     if(area.getCaretPosition() < s.length()-1){
          JOptionPane.showMessageDialog(TEdit.getFrame(),"Reached the beginning of the text");
          return;
      }
           if(area.getCaretPosition()-s.length()<=0){
               area.setCaretPosition(txt.length()-1);
           }
           int foundAt = txt.substring(0,area.getCaretPosition()-s.length()).lastIndexOf(s);
           
           if(foundAt == -1){
               JOptionPane.showMessageDialog(TEdit.getFrame(),"Reached the beginning of the text");
               return;
           }
               area.setCaretPosition(foundAt);
               area.select(foundAt,foundAt+s.length());
}