page searcher

Hi

need to make sercher JTextComponent.

As in every searcher you've got:

Ctrl+F -> window-> SEARCH GOES DURING THE TYPING, NOT AFTER ENTER

PRESSING

QUESTION - HOW TO HIGHLIGHT (maby better say extract) FOUNDED TEXT

Highliter class -I've also thought so - but it's just for painting text background.

thanks

[363 byte] By [kpba] at [2007-11-26 21:26:46]
# 1

> QUESTION - HOW TO HIGHLIGHT (maby better say extract)

> FOUNDED TEXT

extract to where? String? what if there are couple of occurences?

> Highliter class -I've also thought so - but it's

> just for painting text background.

And what do You expected for highliting?

hellbindera at 2007-7-10 3:07:39 > top of Java-index,Desktop,Core GUI APIs...
# 2
okwhen you in any broser do Ctrl+f, type smth, press Enter -- you can see foundedtext becouse of its changed background colorhope its more understandable))
kpba at 2007-7-10 3:07:39 > top of Java-index,Desktop,Core GUI APIs...
# 3
So what is done in browsers is painting text background, isn't it?
hellbindera at 2007-7-10 3:07:39 > top of Java-index,Desktop,Core GUI APIs...
# 4
yeah,but when you press mouse - this highlight - desappears - that's what i wantthank
kpba at 2007-7-10 3:07:39 > top of Java-index,Desktop,Core GUI APIs...
# 5
so you want the text to be highligted after the user presses mouse on a text component?
hellbindera at 2007-7-10 3:07:39 > top of Java-index,Desktop,Core GUI APIs...
# 6
noi see that i'm bad explanator.if you have iexplorer, or better mozilla - you can see howtext search works there. i need same.I need to mark (hope its right word) founeded words as in this browsers
kpba at 2007-7-10 3:07:39 > top of Java-index,Desktop,Core GUI APIs...
# 7

hope You are talking of something like that. Check it out:

import java.awt.BorderLayout;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTextArea;

import javax.swing.JTextField;

import javax.swing.event.DocumentEvent;

import javax.swing.event.DocumentListener;

public class Forum extends JPanel implements DocumentListener {

JTextField field;

JTextArea tarea;

public Forum() {

super(new BorderLayout());

field = new JTextField(10);

tarea = new JTextArea("This is a sample text.", 20, 20);

field.getDocument().addDocumentListener(this);

add(field, BorderLayout.NORTH);

add(tarea, BorderLayout.CENTER);

}

public void changedUpdate(DocumentEvent e) {}

public void insertUpdate(DocumentEvent e) {

int start = tarea.getText().indexOf(field.getText());

if (start<0){

tarea.setSelectionEnd(-1);

return;

}

int end = start+field.getText().length();

tarea.setSelectionStart(start);

tarea.setSelectionEnd(end);

}

public void removeUpdate(DocumentEvent e) {

int start = tarea.getText().indexOf(field.getText());

if (start<0){

tarea.setSelectionEnd(-1);

return;

}

int end = start+field.getText().length();

tarea.setSelectionStart(start);

tarea.setSelectionEnd(end);

}

public static void main(String[] args) {

JFrame frame = new JFrame("Forum");

frame.setContentPane(new Forum());

frame.pack();

frame.setDefaultCloseOperation(3);

frame.setVisible(true);

}

}

hellbindera at 2007-7-10 3:07:39 > top of Java-index,Desktop,Core GUI APIs...
# 8
was Your problem solved kpb?
hellbindera at 2007-7-10 3:07:39 > top of Java-index,Desktop,Core GUI APIs...
# 9
yeah!!!!!!!!thank youits what i've looking for
kpba at 2007-7-10 3:07:39 > top of Java-index,Desktop,Core GUI APIs...
# 10
nicebut its not workfield.getDocument().equals(tarea.getDocument()) == falsehow it can be?
kpba at 2007-7-10 3:07:39 > top of Java-index,Desktop,Core GUI APIs...