简体   繁体   English

JButton在JFrame中的图片上方-摆动

[英]JButton over Image in JFrame - swing

I have an opened an image using JFrame in java. 我在Java中使用JFrame打开了一个图像。 Now I want to display a button at particular location in that image to do certain task. 现在,我想在该图像的特定位置显示一个按钮,以执行某些任务。 But i feel it to be more challenging. 但是我觉得这更具挑战性。 Please give me an idea or source code to do my task. 请给我一个想法或源代码来完成我的任务。

waiting for valuable reply 等待有价值的答复

You can make a JComponent and use a MouseListener to see if the user clicks in the area of the image. 您可以制作一个JComponent并使用MouseListener来查看用户是否单击了图像区域。 Thus you can execute your action if the user clicks. 因此,如果用户单击,您可以执行操作。

Look at the LayeredPane layout manager . 查看LayeredPane布局管理器 This will easily overlay a button on a picture. 这将轻松地将按钮覆盖在图片上。

Why don't you try to just add a click the image to run the command you want just like button use mouse listener. 您为什么不尝试仅添加单击图像来运行所需的命令,就像按钮使用鼠标侦听器一样。 or just prompt a JOption pane for options for the Image? 还是只是提示JOption窗格以提供图像选项?

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

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