How to stop JButton background only appearing as a border

问题: I'm creating an AbstractColorChooserPanel for recent colours (in a 4 * 4 grid) and while setting the background colour for the recent colours it only appears as a border to...

问题:

I'm creating an AbstractColorChooserPanel for recent colours (in a 4 * 4 grid) and while setting the background colour for the recent colours it only appears as a border to the button instead of filling it.

According to this the code below should work:

button.setBackground(Color.RED);
button.setOpaque(true);

Ive also tried adding

button.setBorderPainted(false);

but all that displays is a grey (standard colour) button with a red border. I have tried putting the code on a button outside the JColorChooser and received the same effect. example

How do I make it so the entire button is filled with the red colour instead of just the border?

EDIT: The problem turned out to be the UIManager (default system look and feel) To solve this I modified the code used in this solution.


回答1:

Try adding this :

button.setContentAreaFilled( false );
  • 发表于 2019-03-29 01:40
  • 阅读 ( 142 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除