下面代码中.我直接用setBackground(Color.red);设置背景颜色根本没用,但是
//Container conPane=getContentPane();
//conPane.setBackground(Color.red);

然后再用 conPane.setBackground(Color.red);中间的那层没有颜色,这是为什么?
还有,如何能让l=new JLabel("移动滚动条可改变背景颜色");
这一句居中显示?
import java.awt.*;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;import javax.swing.*;
public class Src extends JFrame {
JTextField text;
s S;
JLabel l;
Src()
{   
//Container conPane=getContentPane();
//conPane.setBackground(Color.red);

l=new JLabel("移动滚动条可改变背景颜色");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBackground(Color.red);
setSize(500,250);
setVisible(true);
setLayout(new GridLayout(3,1,1500,0));
S=new s();
setBackground(Color.red);
add(l);
add(S);
}
public static void main(String[] args)
{
            new Src();
}
class s extends JPanel implements  AdjustmentListener
{   JTextField t;
     JScrollBar bar;
     JScrollBar bar1;
     JScrollBar bar2;
s()
{   
bar=new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255);
bar1=new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255);
bar2=new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255);
setLayout(new FlowLayout());
bar.setPreferredSize(new   Dimension(100,20)); 
bar1.setPreferredSize(new   Dimension(100,20)); 
bar2.setPreferredSize(new   Dimension(100,20)); 
add(bar);
add(bar1);
add(bar2);
bar.addAdjustmentListener(this);
bar1.addAdjustmentListener(this);
bar2.addAdjustmentListener(this);

}
public void adjustmentValueChanged(AdjustmentEvent e) {

}

}}