setbackground为什么没用呢?
package bornthisway;
import java.awt.*;
import javax.swing.*;
public class BornThisWay extends JFrame {
public Container container = null;
JLabel soil=new JLabel();
public BornThisWay() {
this.setTitle("test");
this.setSize(810, 510);
setResizable(false);
setLocationRelativeTo(null);
container = this.getContentPane();
container.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
soil.setBackground(Color.DARK_GRAY);
soil.setText("0,250==============================================================================================================");
container.add(soil);
soil.setSize(810, 10);
soil.setLocation(0, 350);
}
public static void main(String[] args) {
new BornThisWay();
}
}
我设置了soil背景色为灰色,可是运行没显示,为什么呢?
------解决方案--------------------
soil.setBackground(Color.DARK_GRAY);前先,
Java code
soil.setOpaque(true);