注册 登录
编程论坛 JAVA论坛

为什么setForeground改不了button的颜色

wancy 发布于 2016-06-03 21:18, 2587 次点击
import java.awt.Frame;
import java.awt.Color;
import java.awt.Button;
import java.awt.FlowLayout;
public class Example
{
    public static void main(String[] args)
    {
        Frame f=new Frame();
        Color c=new Color(255,255,0);
        f.setBackground(c);
        f.setSize(500,500);
        f.setLocation(300,300);
        //f.setLayout(new FlowLayout());
        Button button=new Button("");
        f.setLayout(null);
        button.setForeground(Color.cyan);
        //button.setBackground(Color.GREEN);
        button.setBounds(50,50,100,100);
        //button.setSize(200,200);
   
        f.add(button);
        
        f.setVisible(true);
    }
}
2 回复
#2
zzjvslove2016-06-04 12:27
按钮上使用setForeground  设置的是按钮上 字体的颜色
按钮上使用setBackground  设置的是按钮的 背景颜色
#3
wancy2016-06-06 17:45
额,明白了
1