也许这个对你有帮助。import java.awt.*; import javax.swing.*; import java.awt.event.*;public class Frame2 extends JFrame { JTextArea jTextArea1 = new JTextArea(); public Frame2() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { Frame2 frame2 = new Frame2(); frame2.show(); } private void jbInit() throws Exception { jTextArea1.setText("jTextArea1I think I do thisjTextArea1I think I do this jTextArea1I " + "think I do this jTextArea1I think I do this jTextArea1I think I do " + "this jTextArea1I think I do this jTextArea1I think I do this jTextArea1I " + "think I do this jTextArea1I think I do this jTextArea1I think I do " + "this jTextArea1I think I do this jTextArea1I think I do this "); jTextArea1.setRows(12); jTextArea1.addMouseListener(new MouseListener(){ public void mouseClicked(MouseEvent e) { System.out.println("fdasfasd"); } public void mouseEntered(MouseEvent e) { ; } public void mouseExited(MouseEvent e){ } public void mousePressed(MouseEvent e) { jTextArea1.selectAll(); jTextArea1.setSelectedTextColor(new Color(100,17,44)); } public void mouseReleased(MouseEvent e) { } }); this.getContentPane().add(jTextArea1, BorderLayout.CENTER); } }好运与你同行。
import javax.swing.*;
import java.awt.event.*;public class Frame2 extends JFrame {
JTextArea jTextArea1 = new JTextArea(); public Frame2() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Frame2 frame2 = new Frame2();
frame2.show();
}
private void jbInit() throws Exception {
jTextArea1.setText("jTextArea1I think I do thisjTextArea1I think I do this jTextArea1I " +
"think I do this jTextArea1I think I do this jTextArea1I think I do " +
"this jTextArea1I think I do this jTextArea1I think I do this jTextArea1I " +
"think I do this jTextArea1I think I do this jTextArea1I think I do " +
"this jTextArea1I think I do this jTextArea1I think I do this ");
jTextArea1.setRows(12);
jTextArea1.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e)
{
System.out.println("fdasfasd");
} public void mouseEntered(MouseEvent e) {
;
} public void mouseExited(MouseEvent e){
}
public void mousePressed(MouseEvent e) {
jTextArea1.selectAll();
jTextArea1.setSelectedTextColor(new Color(100,17,44)); }
public void mouseReleased(MouseEvent e) {
} });
this.getContentPane().add(jTextArea1, BorderLayout.CENTER); }
}好运与你同行。