修改面板的背景颜色

package button;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class buttonFrame extends JFrame{
	private JPanel buttonPanel;
	private static final int D_width=300;
	private static final int D_height=200;
	public static void main(String args[]){
		JFrame frame = new buttonFrame();
		frame.setTitle("buttonFrame");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

	public buttonFrame(){
		setSize(D_width,D_height);

		JButton yellowButton = new JButton("Yellow");
		JButton blueButton = new JButton("Blue");
		JButton redButton = new JButton("Red");

		buttonPanel = new JPanel();

		buttonPanel.add(yellowButton);
		buttonPanel.add(blueButton);
		buttonPanel.add(redButton);

		add(buttonPanel);

		ColorAction yellowAction = new ColorAction(Color.YELLOW);
		ColorAction blueAction = new ColorAction(Color.BLUE);
		ColorAction redAction = new ColorAction(Color.RED);

		yellowButton.addActionListener(yellowAction);
		blueButton.addActionListener(blueAction);
		redButton.addActionListener(redAction);

	}

	private class ColorAction implements ActionListener{
		private Color backgroundColor;
		public ColorAction(Color c){
			backgroundColor=c;
		}
		public void actionPerformed(ActionEvent event){
			buttonPanel.setBackground(backgroundColor);
		}
	}
}

  

时间: 2024-07-29 23:06:56

修改面板的背景颜色的相关文章

ios修改NavigationController的背景颜色

在ios开发的过程中,我们经常需要修改NavigationController的背景颜色,当使用方法[self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]]时,运行的结果并不能修改北京颜色: 现在提供一种新方法来解决这个问题: 写一个NavigationBar写一个类别: @interface UINavigationBar (BackgroundColor) //设置navigationBar

【BIRT】修改BIRT的背景颜色

修改BIRT报表的背景颜色都在这里了 在BIRT的webcontent/birt/styles/目录下有如下文件列表: dialogbase.css文件修改 dialogbase_rtl.css文件修改   style.css文件修改 修改一: 修改二: 以上是根据自我需求修改,如果需要修改其他颜色,或特定位置颜色,参看css文件具体定制即可. 原文地址:https://www.cnblogs.com/OliverQin/p/9597543.html

VC OnCtlColor函数来修改控件背景颜色

CWnd::OnCtlColor afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor ); 返回值:OnCtlColor必须返回一个刷子句柄,该刷子将被用于画出控件的背景. 参数: pDC 包含了子窗口的显示设备环境的指针.可能是临时的. PWnd 包含了要求颜色的控件的指针.可能是临时的. NCtlColor 包含了下列值,指定了控件的类型: · CTLCOLOR_BTN 按钮控件 · CTLCOLOR_DLG 对话框

修改UISearchBar的背景颜色

当你看到这篇博客你就已经发现了用_searchBar.backgroundColor = [UIColor clearColor];来设置UISearchBar的颜色完全没有效果: 并且,有些方法是想通过遍历出UISearchBarBackground来移除它实现背景透明,也并没有什么卵用. 下面这个方法,你不用纠结它是怎么实现的,直接复制拿去用: _searchBar.backgroundImage = [self imageWithColor:[UIColor clearColor] siz

PHPStorm怎么修改选中的背景颜色呢?

File -> Settings -> editor ->color&fonts->general->下拉框中的selection background->点击后边的小方框框选择你喜欢的颜色即可 ps:有些主题的选中颜色很淡,这个操作还是蛮实用的.

如何修改Eclipse的背景颜色

一.设置方式 结果如下:

JavaScript节点的方式修改元素的背景颜色

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> div { width: 300px; height: 400px; border: 1px solid red; } </style> </head> <body> <

小程序动态修改page的背景颜色

wxml: 把所有的页面内容用一个class为page的view标签包裹起来 <view class="page" style="background-color:{{bgColor}}"> ... </view> wxss: .page { display: block; min-height: 100%; width: 100%; position: absolute; left: 0; top: 0; z-index: 1; } Js:

导航条的自定义:背景颜色设置,按钮标题图片设置,图片坐标修改

一.修改系统原生导航条 修改导航条背景颜色 self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#2295f2"]; 自定义导航条按钮 self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"btn-menu-h&q