Como deixar selecionado o conteudo de um JTextArea? (URGENTE)

Queria selecionar o trecho de um texto que está num JTextArea (deixar como se tivesse passado o mouse sobre o trecho ) e não estou conseguindo fazer…

Tentei usar os métodos
setSelectionEnd e setSelectionStart pra selecionar o trecho e select para selecionar mas não consegui…

Alguém pode me ajudar?

VLW

Você pode usar somente o método select(int selectionStart, int selectionEnd). Caso queira selecionar o texto todo, use selectAll().
Se por acaso isso não funcionar (Aqui funcionou), por favor, poste seu código, ok?

public class TextAreaDemo1 extends JFrame{
	private JTextArea t1, t2;
	private JButton buttons[];
	private JPanel buttonPanel;
	private String text1;
	private int cliques;
	
	String f1 [] ;
	int vet1 [];
	
	
	
	public TextAreaDemo1 (){
		super ("Translator Demo");
		
		
		buttonPanel= new JPanel();
		buttons = new JButton [2];
		buttons [0] = new JButton ("Abrir Arquivo");
		buttonPanel.add (buttons [0]);
	
		cliques = 1;
		
		buttons [0].addActionListener (
				new ActionListener(){
					public void actionPerformed (ActionEvent e)
					{
						openFile();
									
						cliques = 1;
					}
					
					}
	);
		
		
		buttons[1]= new JButton ("Traduzir >>>");
		buttonPanel.add (buttons [1]);
		
		buttons [1].addActionListener (
				new ActionListener(){
					public void actionPerformed (ActionEvent e)
					{	
						
						t2.setText(" ");	//limpa área de texto
						
						
						String s = t1.getSelectedText();	//texto selecionado
						String s1= t1.getText();			//texto da área de texto
						
						
						int lentexto = s1.length();	//tamanho do texto
						String output= new String ();
						
						StringTokenizer tokens1 = new StringTokenizer (s1);
						StringTokenizer tokens = new StringTokenizer (s);
					
						int it = t1.getSelectionStart();	//inicio da selação
						
						char ch [] = new char [it];
						char ch2 [] = new char[lentexto];
						
						s1.getChars(0, lentexto, ch2, 0);
						
					
							
						//copia caracteres do string para o array char
						s1.getChars(0, it, ch, 0);
						for (int i =0;i<ch.length; i++)
							output += ch[i];
						
						
						StringTokenizer tokens2 = new StringTokenizer (output);
						
						int count = tokens.countTokens();	//n° de tokens no trecho selecionado
						int count1 = tokens1.countTokens();	//n° de tokens no texto
						int count2 = tokens2.countTokens();	//n° de tokens antes do trecho selecionado
						
						String f[] = new String [count1];
						int vet [ ]= new int [count1];
						
						int esp1=0;
						String tab [] = new String [count1-1];
						
						//pegando os delimitadores entre os tokens
						//tab[0] contem os Whitespace entre o 1° e o 2° token, 
						//tab[1] contem os Whitespace entre o 2° e o 3° token
						//e assim sucessivamente
						
						for (int i =0;i<count1-1; i++){
							while (Character.isWhitespace(ch2[esp1])==false){
								 char st [ ] =new char[1];
								 s1.getChars(esp1,esp1+1,st, 0);
								System.out.print(st);
								esp1++;
								
							}
								StringBuffer sn = new StringBuffer();
							while (Character.isWhitespace(ch2[esp1])==true){
								char st [ ] =new char[1];
								 s1.getChars(esp1,esp1+1,st, 0);
							
								 String h = new String(s1.substring(esp1, esp1+1));
								sn.append(h);
								esp1++;
							}
							
							
							tab[i]= sn.toString();
							System.out.print(tab[i]);
							
						}
								
						int l = 0;
						if (cliques ><=1){	//primeira seleção no texto					
							while (tokens1.hasMoreTokens()){
								String m = tokens1.nextToken();
								f[l]=m; 				//token do texto
								vet [l] = m.length();	//tamanho do token
							    l++;	   
							}
							f1=f;
						    vet1=vet;
						}
						
						cliques++;
					    
					   
					    int k = count2; //numero de tokens antes da seleção
					    //pedindo tradução dos tokens do trecho selecionado
					    while (tokens.hasMoreTokens()){
							String m1 = tokens.nextToken();
							text1 = JOptionPane.showInputDialog ("Entre com a tradução de '" + m1 + "'" );
								f1[k]= text1;			//tradução
								vet1[k] = m1.length();  //tamanho da tradução
								
								k++;
						}
					    
						
					    //traduzindo texto
					    esp1=0;
					    for (l=0; l<count1; l++){
					    	if (esp1><count1-1)
								t2.append(f1[l]+tab[esp1]);
								else
									t2.append(f1[l]);
					    	esp1++;
					    }
					    	
						
					    int it2 = 0;
					    //calculando inicio do trecho a ser selecionado
					    for (int i=0; i><count2; i++)
					    	it2+=vet1[i]+ tab[i].length();
					    System.out.print(" ' " + it2 + " ' " );
					    
					    //calculando fim do trecho a ser selecionado
					    int it3=it2;
					    for (int i=count2; i><count2+count-1; i++)
					    	it3+=vet1[i]+ tab[i].length();
					    System.out.print(it3+vet[count1]);
					 
					    t2.select(it2,it3);
					    
					    
					}
					
				
				
					
				}
	
					
		
	);

>

Por favor, não leve a mal, mas como seu código tava meio bagunçado e com alguns erros, fiz um exemplinho meio tosco mas que dá pra vc ver a utilização do JTextArea. Copie o código e execute, ok?

package customJTextField;

import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.LineBorder;

public class TextAreaDemo2 extends JFrame {
	private JTextArea 
		txaCopy, 
		txaPaste
	;
	private JButton
		btnCopy,
		btnClearCopy,
		btnClearPaste,
		btnFindCopy,
		btnFindPaste,
		btnExit
	;
	
	private final int
		TXA_W = 300,
		TXA_H = 300,
		BTN_W = 115,
		BTN_H = 25
	;
	
	public TextAreaDemo2() {
		instanciateComponents();
		configGUI();
	}

	private void instanciateComponents() {
		txaCopy = new JTextArea(
			"Sonho que se sonha só\n" +
			"É só um sonho que se sonha só\n" +
			"Mas sonho que se sonha junto é realidade"
		);
		txaCopy.setWrapStyleWord(true);
		txaCopy.setBounds(5, 5, TXA_W, TXA_H);
		
		btnClearCopy = new JButton("Limpar");
		btnClearCopy.setBounds(
			txaCopy.getX(), 
			txaCopy.getY() + txaCopy.getHeight(), 
			txaCopy.getWidth() / 2, 
			BTN_H
		);
		btnClearCopy.addActionListener(
			new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					txaCopy.setText("");
				}
			}
		);

		btnFindCopy = new JButton("Procurar texto");
		btnFindCopy.setBounds(
			btnClearCopy.getX() + btnClearCopy.getWidth(), 
			btnClearCopy.getY(), 
			btnClearCopy.getWidth(), 
			BTN_H
		);
		btnFindCopy.addActionListener(new FindButtonHandler(txaCopy));
		
		btnCopy = new JButton(">> Copiar >>");
		btnCopy.setBounds(
			txaCopy.getX() + TXA_W + 5, 
			(TXA_H - BTN_H) / 2, 
			BTN_W, 
			BTN_H
		);
		btnCopy.addActionListener(new CopyButtonHandler());
		
		txaPaste = new JTextArea();
		txaPaste.setWrapStyleWord(true);
		txaPaste.setEditable(false);
		txaPaste.setBackground(new Color(210, 210, 210));
		txaPaste.setBounds(
			btnCopy.getX() + BTN_W + 5,
			txaCopy.getY(),
			TXA_W, 
			TXA_H
		);

		btnClearPaste = new JButton("Limpar");
		btnClearPaste.setBounds(
			txaPaste.getX(), 
			txaPaste.getY() + txaPaste.getHeight(), 
			txaPaste.getWidth() / 2, 
			BTN_H
		);
		btnClearPaste.addActionListener(
			new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					txaPaste.setText("");
				}
			}
		);

		btnFindPaste = new JButton("Procurar texto");
		btnFindPaste.setBounds(
			btnClearPaste.getX() + btnClearPaste.getWidth(), 
			btnClearPaste.getY(), 
			btnClearPaste.getWidth(), 
			BTN_H
		);
		btnFindPaste.addActionListener(new FindButtonHandler(txaPaste));
		
		btnExit = new JButton("Sair");
		btnExit.setBounds(
			btnCopy.getX(), 
			btnClearCopy.getY() + BTN_H + 10,
			BTN_W,
			BTN_H
		);
		btnExit.addActionListener(
			new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					System.exit(0);
				}
			}
		);
	}

	private void configGUI() {
		JScrollPane 
			scrlCopy = new JScrollPane(txaCopy),
			scrlPaste = new JScrollPane(txaPaste);
		;
		
		scrlCopy.setBounds(txaCopy.getBounds());
		scrlCopy.setBorder(
			BorderFactory.createTitledBorder(new LineBorder(Color.blue), "Texto fonte")
		);

		scrlPaste.setBounds(txaPaste.getBounds());
		scrlPaste.setBorder(
			BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Texto Copiado")
		);
		
		Container c = getContentPane();
		c.setLayout(null);
		c.add(scrlCopy);
		c.add(scrlPaste);
		c.add(btnCopy);
		c.add(btnClearCopy);
		c.add(btnClearPaste);
		c.add(btnFindCopy);
		c.add(btnFindPaste);
		c.add(btnExit);
		setTitle("Testando JTextArea");
		setSize(
			txaPaste.getX() + txaPaste.getWidth() + 12, 
			btnExit.getY() + btnExit.getHeight() + 40
		);
		setLocation((800 - getWidth())/2, (600 - getHeight())/2);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}
	
	public static void main(String[] args) {
		TextAreaDemo2 app = new TextAreaDemo2();
		app.show();
	}

	private class FindButtonHandler implements ActionListener {
		private JTextArea txa;
	
		public FindButtonHandler(JTextArea txa) {
			this.txa = txa;
		}
		
		/* ********************************************
		 * Este método é o que realmente te interessa *
		 * ********************************************/
		public void actionPerformed(ActionEvent e) {
			String find = null;
			try {
				find = JOptionPane.showInputDialog(
					txa.getParent(), 
					"Insira o texto procurado"
				).toLowerCase();
			} catch (Exception exp) {
				return;
			}
			int findPos = txa.getText().toLowerCase().indexOf(find);
			
			txa.grabFocus();
			txa.select(findPos, findPos + find.length());
		}
	}

	private class CopyButtonHandler implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			txaPaste.insert(
				txaCopy.getSelectedText(), 
				txaPaste.getCaretPosition()
			);
		}
	}
}

Qualquer dúvida, estamos aí!