英文:
How to get the color beneath an opaque JPanel?
问题
以下是翻译好的部分:
有没有一种方法可以获取不透明 JPanel 下方的颜色?
我有两个 JPanel,一个红色的和一个蓝色的(它们是动画的)。我想根据覆盖其上的 JPanel 来获取表面的颜色。
在下面的图片中,小方块是一个不透明的 JPanel,我想获取其下方 JPanel 的颜色。
英文:
Is there is a way to get the color underneath an opaque JPanel?
I have two JPanels, a red one and a blue one (they are animated). I want to get the color of a surface according to the JPanel that passes over it.
In following images, the small borderd square is an opaque JPanel, and I want to retrieve the color of the JPanel beneath.
答案1
得分: 0
不太确定您在问什么。但是假设您知道矩形的 x/y 位置,您可以使用:
- 
Container类的getComponentAt(...)方法。一旦获得父面板,您可以使用getBackground()方法来获取颜色。 - 
或者,您可以使用
Robot类和getPixelColor(...)方法。 
英文:
Not really sure what you are asking. But assuming you know the x/y location of the rectangle you could use:
- 
The
getComponentAt(...)method of theContainerclass. Once you get the parent panel you use the getBackground()` method to get the Color - 
Or, you can use the
Robot class and thegetPixelColor(...)` method. 
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。




评论