Java中设置全局鼠标按下颜色

Java中设置全局鼠标按下颜色,代码如下:

package mouse;

import java.awt.Color;
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.UIManager;

public class MousePressedTest extends JFrame {

	private static final long serialVersionUID = -6740703588976621222L;

	public MousePressedTest() {
		super("鼠标点击测试");
		Container c = this.getContentPane();

		JButton jButton = new JButton("测试");
		jButton.setBounds(100, 60, 85, 35);
		jButton.setForeground(Color.black);
		jButton.setBackground(Color.white);
		jButton.setBorder(BorderFactory.createLineBorder(Color.gray));
		jButton.setFocusPainted(false);
		c.add(jButton);

		this.setSize(300, 200);
		this.setLayout(null);
		this.setUndecorated(false);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public static void main(String[] args) {
		new MousePressedTest();
		// 设置全局按钮按下颜色
		Color pColor = new Color(100, 200, 255);
		UIManager.put("Button.select", pColor);
	}
}

希望对你有所帮助,欢迎订阅我的博客!

猜你喜欢

转载自blog.csdn.net/qq_35923287/article/details/89506315