为什么在JTextArea中画矩形时,矩形框只是一闪而过?怎么让矩形框一直保持呢?
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JTextArea;
import javax.swing.JFrame;
public class test extends JFrame {
JTextArea jta = new JTextArea();
public test() {
super.setTitle("test");
this.add(jta);
this.setSize(500,500);
this.setVisible(true);
}
public static void main(String[] args) {
new JTextAreaHex_drawRectangle();
}
}
class JTextAreaHex_drawRectangle extends javax.swing.JTextArea {
test t = new test();
public JTextAreaHex_drawRectangle() {
this.paintComponent(t.getGraphics());
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.RED);
g.drawRect(0, 0, 100, 100);
}
}