简体   繁体   English

使用图像而不是JDialog / frame来保存摆动组件?

[英]Using an image instead of JDialog/frame to hold swing components?

I currently have a JDialog (class that implements JDialog and is constructed like a jframe), and has 3 swing buttons placed on it. 我目前有一个JDialog(实现JDialog并像jframe一样构造的类),并在上面放置了3个摆动按钮。 Currently I have it set, undecorated = true, to hide the outer frame. 目前,我将其设置为undecorated = true,以隐藏外部框架。 Is there any way to use my image to replace the default square frame? 有什么方法可以使用我的图像替换默认的方形框架?

This is what I aim for : 这是我的目标:

http://i.stack.imgur.com/6w9kh.jpg

The blue square with shadow is the pre made image. 带有阴影的蓝色正方形是预制的图像。

Regards 问候

The blue square with shadow is the pre made image. 带有阴影的蓝色正方形是预制的图像。

Well, the best way would be to set the background of the panel and then add a ShadowBorder to the panel. 好吧,最好的方法是设置面板的背景,然后将ShadowBorder添加到面板。 This will provide you with far more flexibility in the future as you can create many panels with different colors and reuse the same ShadowBorder instead of having to create an Image every time. 这将为您将来提供更大的灵活性,因为您可以创建许多具有不同颜色的面板并重复使用相同的ShadowBorder,而不必每次都创建图像。 I don't have an example of a ShadowBorder, but you might find one if you search the web. 我没有ShadowBorder的示例,但是如果您在网上搜索,可能会找到一个示例。

Is there any way to use my image to replace the default square frame? 有什么方法可以使用我的图像替换默认的方形框架?

But if you really want to use your premade Image, then you can just: 但是,如果您真的想使用预制图像,则可以:

  1. create a JLabel and add your Image to the label as an Icon 创建一个JLabel并将您的Image作为图标添加到标签
  2. add the label to the dialog 将标签添加到对话框
  3. set the layout manager of the label 设置标签的布局管理器
  4. add your components to the label. 将您的组件添加到标签。

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

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