java jbutton 背景颜色_java – 在Windows上设置JButton背景颜色
我有一个JButton,我想将背景设置为一种颜色.
JButton button = new JButton();
button.setVisible(true);
button.setPreferredSize(new Dimension(student_scroll.getWidth(), 50));
button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 1));
button.setBackground(Color.BLACK);
button.setForeground(Color.WHITE);
button.setOpaque(true);
我用这个用于mac,它出现了,因为我想要它.但是,在Windows上尝试它时,前景是白色的(应该如此),但背景是空的.
说添加button.setContentAreaFilled(false);我做了但没有效果.大多数人说要添加button.setOpaque(true);我也已经这样做了.
还有什么我必须做的,它会出现黑色背景?
编辑
根据要求,SSCCE:
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class MainSwing extends JFrame {
private static final long serialVersionUID = -8231889836024827530L;
public static void main(String[] args) {
try {
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Test");
UIManager.put("ScrollBarUI", "main.CustomScrollBarUI");
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(ClassNotFoundException e) {
System.out.println("ClassNotFoundException: " + e.getMessage());
}
catch(InstantiationException e) {
System.out.println("InstantiationException: " + e.getMessage());
}
catch(IllegalAccessException e) {
System.out.println("IllegalAccessException: " + e.getMessage());
}
catch(UnsupportedLookAndFeelException e) {
System.out.println("UnsupportedLookAndFeelException: " + e.getMessage());
}
SwingUtilities.invokeLater( new Runnable() {
public void run() {
JFrame frame = new JFrame() {
Container c = getContentPane();
JButton button = new JButton("Hello");
{
button.setText("Hello");
button.setVisible(true);
button.setPreferredSize(new Dimension(100, 50));
button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 1));
button.setBackground(Color.BLACK);
button.setForeground(Color.WHITE);
button.setOpaque(true);
c.add(button);
}
};
frame.setSize(500, 500);
frame.setBackground(Color.BLACK);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
似乎该问题与该行有关:UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());当我删除它时,按钮是黑色的.
java jbutton 背景颜色_java – 在Windows上设置JButton背景颜色相关推荐
- Windows上设置Docker共享盘符
Windows上设置Docker共享盘符 Docker中的settings里的Shared Drives 选择对应盘符后,点击Apply后无法生效,没办法选择对应盘符进行分享. Exceptions: ...
- 在windows上设置代理服务器
在windows上设置代理服务器 1.安装Apache环境 下载地址:http://httpd.apache.org/docs/current/platform/windows.html#down 只 ...
- java实现图片变色_java 图片裁剪上传变红等失真现象、cmyk颜色模式图片裁剪异常现象处理...
1.本文仅为了提供图片上传过程中,部分java图片处理代码. 2.以下代码可以解决部分图片上传裁剪后整体变红等失真现象. 3.以下代码支持cmyk颜色模式的图片上传裁剪./** * 图片裁剪 * @p ...
- JAVA实现negotiate认证_Java SSO windows AD spring4 – Negotiate Header无效:
嗨,我正在尝试使用JAVA和spring设置SSO.为此,我使用此文档:http://docs.spring.io/spring-security-kerberos/docs/1.0.0.RELEAS ...
- Java知多少(96)绘图之设置字型和颜色
Java绘图中,显示文字的方法主要有三种: (1)drawString(String str,int x,int y):在指定的位置显示字符串. (2)drawChars(char data[],in ...
- python3设置编码背景颜色_在pythongtk3中设置条目背景颜色并设置回defau的最佳方法...
我将首先解决您提到的问题,因为这些问题可以深入了解GTK和OP的代码.主要问题的答案(以及执行此操作的适当代码)位于答案的底部.If I insert a text, not containing s ...
- windows如何设置护眼颜色
对于windows窗口,我们许多时候会觉得有点刺眼,总是想将其颜色设置成自己喜欢的颜色,但往往却又不知道如何操作,今天就来教一教大家如何设置windows很多窗口颜色的几种方法: 1.打开注册表 调出 ...
- FFmpeg在Windows上设置dshow mjpeg编码+libyuv解码显示测试代码
之前在https://blog.csdn.net/fengbingchun/article/details/103444891中介绍过在Windows上通过ffmpeg dshow设置为mjpeg编解 ...
- 如何在Windows上设置BitLocker加密
BitLocker is a tool built into Windows that lets you encrypt an entire hard drive for enhanced secur ...
最新文章
- Struts2中的struts.multipart.saveDir的配置
- Android之二维码生成与扫描
- python怎么捕获mysql报错
- 移动**21*设置无法接通_电话打得出去,但别人打你的电话提示用户无法接通,是怎么回事?...
- 【今晚七点半】:主编对话李宇翔——我所经历的“前端”开发
- 2021前端高频面试题整理,附答案
- 云端计算机可以玩游戏么,手机掌上云电脑是什么?为什么可以玩PC游戏?
- 信息学奥赛一本通(1313:【例3.5】位数问题)
- canvas绘图粒子扩散效果【原创】
- 怎么管理Websphere应用服务器?
- Populating Next Right Pointers in Each Node I or II
- Windows上搭建Git服务器
- R语言学习之R程序包安装
- 排序算法(java)——— 堆排序
- 计算机上网记录怎么清除,如何清除上网记录?
- 简单说一下寄存器寻址
- 使用SINet进行伪装目标检测
- 第十六期 CyanogenMod 小米3W刷机《手机就是开发板》
- Java 添加Word文本水印、图片水印
- Kronecker积及其等式性质