Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > Java
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 12-01-2004, 12:14 PM   #1 (permalink)
freesoft_2000
Code Monkey
 
Join Date: Oct 2004
Posts: 51
freesoft_2000 is on a distinguished road
Exclamation Text Searching

Hi everyone,

I have a textpane with some text inside and trying to search for a particular text in the textpane by highlighting it. Basically i the main function that does this is as follows

TextPane is an instance of my JTextPane
Code:
public void findtext(int pos1, String str1) { //This function finds the specified text in the document in the JTextPane //according the downwards position of the caret in the JTextPane Document Document1 = null; String str2 = null; int w = 0, w1 = 0, w2 = 0; //The below command line gets the document of the JTextPane Document1 = TextPane1.getDocument(); System.out.println("" + pos1); try { //The below command line gets the text of the document according to //the downwards position of the caret in the JTextPane str2 = Document1.getText(pos1, Document1.getLength() - pos1); //The below two command lines converts the text in the document and the //the text to be searched both to lower case letters //str1 = str1.toLowerCase(); //str2 = str2.toLowerCase(); //The below command line gets the length of the text to be searched w2 = str1.length(); } catch(Exception e) { Label2.setText("A caret position error has occurred"); } //The below command line gets the index of the searched text in the document w = str2.indexOf(str1); if(w == -1) { //In this if statement TextPane1 is gained focus when the searched text //is not found in the document and the function is returned TextPane1.grabFocus(); Label2.setText("The text that was searched was not found"); return; } else { Label2.setText(""); //In this else statement if the searched text is found in the document //the text in the document is selected with respect to the current //caret position in the JTextPane w1 = (w + pos1); TextPane1.select(w1, w1 + w2); TextPane1.grabFocus(); } }
The problem is that the first time that i search the jtextpane the above function works Ok but when i try to do it again only the last text in the jtextpane is selected

I really do not know what is wrong and hope someone can help me with this problem.

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
__________________

Last edited by Belisarius : 12-01-2004 at 12:51 PM.
freesoft_2000 is offline   Reply With Quote
Old 12-01-2004, 12:58 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
I beautified the code, and put it in code tags.

I don't see the problem off the top of my head. When you say the last text, you mean the last matching instance, as opposed to all matching instances?
__________________
GitS
Belisarius is offline   Reply With Quote
Old 12-02-2004, 07:38 AM   #3 (permalink)
freesoft_2000
Code Monkey
 
Join Date: Oct 2004
Posts: 51
freesoft_2000 is on a distinguished road
Hi everyone,

First let me say thank you belisarius for you adding the code tags and beautifying the code.

Belisarius you said

" When you say the last text, you mean the last matching instance, as opposed to all matching instances?"

Yes you are absolutely right and that is exactly what i mean. I tried looking over my code but still could not find out what's wrong. Maybe someone could take a look at my code see or tell where and what i gone wrong.


Any help is greatly appreciated

Thank You

Yous Sincerely

Richard West
__________________
freesoft_2000 is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[MySQL] blob vs text redhead PHP 2 03-29-2004 11:15 PM
Read and Write to a Text File sde C# 0 02-23-2004 06:44 AM
An Introduction to XHTML/CSS Rie HTML / CSS 0 03-07-2003 06:50 PM
Capturing web page text vaclav VB 6 0 02-24-2003 02:42 PM
Working with Text Files rdove Perl 4 10-21-2002 06:06 PM


All times are GMT -8. The time now is 09:30 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle