java - 面板的背景颜色
问题描述
/*
* 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)
,但它不能改变背景。你们能帮帮我吗?提前致谢。
解决方案
尝试这个
frame.getContentPane().setBackground(Color.GREEN);
推荐阅读
- c# - 带有 EF Core 的适用于 iOS 的 SQLite 3
- phpstorm - 使用 Code Iris 或 SketchIt!PhpStorm 2019.2 中的插件
- java - 执行此功能的更好或更标准的方法是什么?
- python - 显示数组内元素的数据类型并将其转换为整数。Python 和 Numpy
- node.js - 使用 Firebase 云功能删除用户存储文件夹
- protocols - 如何使用@Published 属性包装器定义协议以包含属性
- opengl - 相同的程序,面向 Open GL 和 Open GL ES 2.0
- c++ - 如何在 C++ 中编写派生类的定义?
- android - Cordova - 一些 Android 手机忽略了 textarea 的 autocapitalize=off
- json - 如何检查 jq 结果是否为空?