首页 > 解决方案 > 面板的背景颜色

问题描述

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package foodmeterproject;

import java.awt.Color;

/**
 *
 * @author al-sany
 */
public class FoodMeterProject {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        FirstFrame frame=new FirstFrame();

        frame.setVisible(true);
        frame.setBackground(Color.green);
    }

}

我想改变我的程序背景。有一个JPanel。我想给它的背景上色。我用frame.setBackground(Color.green),但它不能改变背景。你们能帮帮我吗?提前致谢。

标签: javaswing

解决方案


尝试这个

frame.getContentPane().setBackground(Color.GREEN);

推荐阅读