失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > java游戏怎么设置背景色_java-将背景色设置为JButton

java游戏怎么设置背景色_java-将背景色设置为JButton

时间:2020-10-18 22:50:58

相关推荐

java游戏怎么设置背景色_java-将背景色设置为JButton

这个问题已经在这里有了答案:>Java Swing button colors1个

我有一个关于将背景色设置为JButton的问题.

似乎此方法仅更改边框的颜色.这是区别(左边是jButton):

有没有办法使背景相同?

我在Windows 8上使用setLookAndFeel.

解决方法:

这将适用于Metal(默认)或Windows PLAF.

import java.awt.*;

import javax.swing.*;

class ColoredButton {

public static void main(String[] args) {

Runnable r = new Runnable() {

@Override

public void run() {

try {

UIManager.setLookAndFeel(

UIManager.getSystemLookAndFeelClassName());

} catch (Exception e) {

e.printStackTrace();

}

JButton b1 = new JButton("Button 1");

b1.setBackground(Color.RED);

// these next two lines do the magic..

b1.setContentAreaFilled(false);

b1.setOpaque(true);

JOptionPane.showMessageDialog(null, b1);

}

};

SwingUtilities.invokeLater(r);

}

}

标签:java,colors,swing,jbutton

来源: https://codeday.me/bug/1009/1882540.html

如果觉得《java游戏怎么设置背景色_java-将背景色设置为JButton》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。