[JTextPane] Récupérer l'index
Bonjour,
J'ai développé une fonction recherche dans un jtextpane... la recherche est bonne mais j'aimerais récupérer l'index du mot trouvé!
Comment faire?
Merci!
ps:
Citation:
labelRec1.setText("Entrez un mot à rechercher") ;
labelRec.setText("Pas de recherche pour le moment") ;
compteurRec = 0 ;
textRec = textField.getText() ; //le mot recherché
textAreaRec = textArea.getText() ; //tout le texte
boolean indice = false;
int index;
String delimiters = "+-*/(),.:; \n\r\f\b\t\'\"\\"; // les délimiteurs
StringTokenizer st = new StringTokenizer(textAreaRec,delimiters,true);
while (st.hasMoreTokens() || indice==true) //Teste s'il existe au moins une sous-chaine disponible à lire dans la chaine.
{
String mot = st.nextToken();
if (mot.compareTo(textRec) == 0)
{
index = textAreaRec.indexOf(mot);
//index = textArea.get ;
System.out.println("l'index du mot!: "+index);
textArea.setSelectionStart(index);
textArea.setSelectionEnd(index + mot.length());
compteurRec = compteurRec + 1 ;
}
}
if(textRec.compareTo("") == 0)
{
labelRec.setText("Pas de recherche pour le moment") ;
}
else if(compteurRec == 0)
{
labelRec.setText("Le mot " + textRec + " n'apparait pas dans le text") ;
}
else
{
labelRec.setText("Le mot : " + textRec + " apparaît " + compteurRec + " fois.") ;
}
[/b]