How to get JButton default background color?

£可爱£侵袭症+ 提交于 2019-12-01 17:31:02

btn.setBackground(new JButton().getBackground());

how about this... it will get the default color of button

myButton.setBackground(null)

changes it back to the default color.

This might help:

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/SystemColor.html

Toolkit.getDesktopProperty(java.lang.String)
Toolkit.getDesktopProperty("control");
// control - The color rendered for the background of control panels and control objects, such as pushbuttons.
Zpkno

Don't try to get background from Jframe or other elements to apply it on the button; if you already changed it do this:

ElementToStyle.setBackground(null);
anthony
  1. make a new button "db"
  2. make a new variable type Color "jbb"
  3. i.e. - Color jbb = db.getBackground();

now the default background color is stored in the Color jbb which you can now use as the color you want to find/use

   Color cbt= jButton6.getBackground();

        String color_button=cbt.getRed()+","+cbt.getGreen()+","+cbt.getBlue();

if you wont get RGB color button try this code

It works both with:

button.setBackground(null);

and

button.setBackground(new JButton().getBackground());

(when you create a new JButton, its background color is initialized as a null color)
So, choose the one you consider to be the best for your project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!