473,326 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

highlighting text

16
Hello

I want to highlight a text in a text area that matches a pattern written in a text field

help me
i need it asap
Mar 17 '07 #1
8 6287
horace1
1,510 Expert 1GB
Hello

I want to highlight a text in a text area that matches a pattern written in a text field

help me
i need it asap
you would
(1) read the pattern from the TextField using getText()
(2) read the text from the TextArea using getText()
(3) serarch for the start and end of the pattern using getIndex()
(4) if found use setSelectionStart() and setSelectionEnd() to highlight the text in the TextArea
Mar 17 '07 #2
tussom
16
you would
(1) read the pattern from the TextField using getText()
(2) read the text from the TextArea using getText()
(3) serarch for the start and end of the pattern using getIndex()
(4) if found use setSelectionStart() and setSelectionEnd() to highlight the text in the TextArea

can u please be more specific like how do i use the "setSelectionStart"
thank u
Mar 17 '07 #3
tussom
16
you would
(1) read the pattern from the TextField using getText()
(2) read the text from the TextArea using getText()
(3) serarch for the start and end of the pattern using getIndex()
(4) if found use setSelectionStart() and setSelectionEnd() to highlight the text in the TextArea

the issue is about highlighting the text after finding it i don't know how to do that i need help quickly please.
Mar 17 '07 #4
tussom
16
you would
(1) read the pattern from the TextField using getText()
(2) read the text from the TextArea using getText()
(3) serarch for the start and end of the pattern using getIndex()
(4) if found use setSelectionStart() and setSelectionEnd() to highlight the text in the TextArea

I have done 1 and 2 but couldn't do 3 and 4 sorry for nagging but can anyone help me please
Mar 17 '07 #5
horace1
1,510 Expert 1GB
the issue is about highlighting the text after finding it i don't know how to do that i need help quickly please.
try this simple program
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import javax.swing.*;
  3.  
  4. public class TextAreaDemo extends JFrame {
  5.    JTextArea resultArea = new JTextArea(10, 50);
  6.  
  7.     public TextAreaDemo() {
  8.         resultArea.setText("abcdefghijklmnopqrst");
  9.         resultArea.setSelectionStart(3);
  10.         resultArea.setSelectionEnd(15);
  11.         JScrollPane scrollingArea = new JScrollPane(resultArea);
  12.  
  13.         JPanel content = new JPanel();
  14.         content.setLayout(new BorderLayout());
  15.         content.add(scrollingArea, BorderLayout.CENTER);
  16.  
  17.         this.setContentPane(content);
  18.         this.setTitle("TextAreaDemo");
  19.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  20.         this.pack();
  21.     }
  22.  
  23.     public static void main(String[] args) {
  24.         JFrame win = new TextAreaDemo();
  25.         win.setVisible(true);
  26.     }
  27. }
Mar 17 '07 #6
tussom
16
try this simple program
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import javax.swing.*;
  3.  
  4. public class TextAreaDemo extends JFrame {
  5.    JTextArea resultArea = new JTextArea(10, 50);
  6.  
  7.     public TextAreaDemo() {
  8.         resultArea.setText("abcdefghijklmnopqrst");
  9.         resultArea.setSelectionStart(3);
  10.         resultArea.setSelectionEnd(15);
  11.         JScrollPane scrollingArea = new JScrollPane(resultArea);
  12.  
  13.         JPanel content = new JPanel();
  14.         content.setLayout(new BorderLayout());
  15.         content.add(scrollingArea, BorderLayout.CENTER);
  16.  
  17.         this.setContentPane(content);
  18.         this.setTitle("TextAreaDemo");
  19.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  20.         this.pack();
  21.     }
  22.  
  23.     public static void main(String[] args) {
  24.         JFrame win = new TextAreaDemo();
  25.         win.setVisible(true);
  26.     }
  27. }


I got that part but the thing is that i want either to highlight or change font of any word that matches the pattern and they may be many so how do i get their index and highlight them accordingly??
Mar 17 '07 #7
tussom
16
I got that part but the thing is that i want either to highlight or change font of any word that matches the pattern and they may be many so how do i get their index and highlight them accordingly??

we have to use the method Highlight (...) but i don't know how ??
sorry again for nagging !
Mar 17 '07 #8
r035198x
13,262 8TB
we have to use the method Highlight (...) but i don't know how ??
sorry again for nagging !
Don't be sorry for nagging. That's how we all learn.

Have a look at this and try to do the hightlight. You can post if you get further problems.
Mar 19 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Adelson Anton | last post by:
Hi all, Ok, this is what I want to do: When you press, say Ctrl+K ( it doesn't matter which event), I want the , say, second word in the document to be highlighted. Anyone has any idea how...
4
by: Bob hotmail.com> | last post by:
Everyone I have been spending weeks looking on the web for a good tutorial on how to use regular expressions and other methods to satisfy my craving for learning how to do FAST c-style syntax...
0
by: Brian Scott | last post by:
I am currently trying to control the syntax highlighting of a richtextbox control whilst the user types. At the moment I have implemented a thread which calls the richTextBox.Invoke on a method...
4
by: Patrick Porter | last post by:
Arrrgh! I have tried everything (ok, not EVERYTHING) but i cant get solve the problem of getting syntax highlighting in a rich textbox. in the code below, im attempting to highlight all of the...
7
by: Leif902 | last post by:
After much searching of google, the closest I can find is highlighting search terms... however, this is not what I wanted to do. Does anyone know how to parse through a specific element (lets say...
14
by: > Adrian | last post by:
Is there a way of stopping text from highlighting in textbox? Many thanks, Adrian.
0
by: Scott | last post by:
Hi, I think I may have finally found a IDE/text editor that I like, but, it still haves one problem. Geany haves syntax highlighting, but it is not very good for Python. It only seems to have...
1
by: thetechgeek | last post by:
Hey all, I've created a pretty nice-looking drop-down menu, and I need to prevent users form highlighting the text in the menu item, because it looks kind of ugly. Here's an snippet of my menu...
1
by: alamodgal | last post by:
hiiiiiii I have a problem in highlighting searching keyword.Actually im using this function for searching Public Function HighLight(ByVal Keyword As String, ByVal ContentFor As String) Dim...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.