简体   繁体   English

Java Swing中背景的六边形是什么?

[英]What is the hexa color of background in Java Swing?

I'm generating a maze by removing edges from a node's neighbor. 我通过从节点的邻居中删除边缘来生成迷宫。 By removal, I meant to draw the removing edge as the original color of the panel. 通过删除,我的意思是将删除边缘绘制为面板的原始颜色。 I currently have to set it to Color.white but it looks odd. 我目前必须将它设置为Color.white但它看起来很奇怪。 So does anyone know the hexa code of background color in Java Swing? 那么有人知道Java Swing中背景颜色的六进制代码吗?

在此输入图像描述

To avoid pointless JPanel creation (just to retrieve background color from it) use the UI constant that holds the default panel background color: 为了避免无意义的JPanel创建(只是为了从中检索背景颜色),请使用包含默认面板背景颜色的UI常量:

Color bg = UIManager.getColor ( "Panel.background" );

This will return different colors with different UIs set. 这将返回不同的颜色,并设置不同的UI。

Using various constants you can also retrieve lots of other default values that way (not just colors). 使用各种常量,您还可以检索许多其他默认值(不仅仅是颜色)。

The original background colour is RGB(238,238,238) or Hex EEEEEE 原始背景颜色为RGB(238,238,238)或Hex EEEEEE

Edit : As @GuillaumePolet pointed out, this may not be the case for all platforms - so the safest way to get it is when you first create your JPanel using code such as the following: 编辑 :正如@GuillaumePolet指出的那样,所有平台可能都不是这样 - 所以最安全的方法是使用以下代码创建JPanel

    JPanel jp = new JPanel();

    Color bg = jp.getBackground();

    int r = bg.getRed();
    int g = bg.getGreen();
    int b = bg.getBlue();

    System.out.println(r);
    System.out.println(g);
    System.out.println(b);

This is how I got 238,238,238 and I'm using Windows on Java 1.7 这就是我得到238,238,238并且我在Java 1.7上使用Windows的方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM