如何获得不透明 JPanel 下方的颜色?

How to get the color beneath an opaque JPanel?

有没有办法在不透明 JPanel 下获得颜色?

我有两个 JPanel,一个红色的和一个蓝色的(它们是动画的)。我想根据经过表面的 JPanel 获得表面的颜色。

在下面的图像中,带边框的小方块是不透明的 JPanel,我想检索下方 JPanel 的颜色。

不太确定你在问什么。但假设您知道矩形的 x/y 位置,您可以使用:

  1. Containerclass的getComponentAt(...)方法。获得父面板后,您可以使用 getBackground()` 方法获取 Color

  2. 或者,您可以使用 Robot class and the getPixelColor(...)` 方法。