你在什么什么地方使用setBackground的?在repaint中试过吗?

解决方案 »

  1.   

    调用setBackground(Color c)的控件的背景有可能是透明的,用setOpaque(false)设定为不透明即可。
      

  2.   

    调用setBackground(Color c)的控件的背景有可能是透明的,用setOpaque(false)设定为不透明即可。如动态的改变,同时加上this.validate();repaint();
      

  3.   

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class MyApp extends Frame
    {
    public MyApp()
    {
    this.addWindowListener (new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    dispose();
    System.exit(0);
    }
    });
    setBackground(Color.red);
    setLayout(new FlowLayout());
    Panel p = new Panel();
    TextArea ta = new TextArea(9,9);
    p.add(ta);
    ta.setText("asdf\n"+"sdddddddddddddddddddddddddddd\n");
    ta.setEditable(false);
    // ta.setEnabled(false);
    add(p); 
    }

    public static void main(String args[])
    {
    System.out.println("Starting App");
    MyApp f = new MyApp();
    f.setSize(100,100);
    f.show(); }
    }