您可以通过多种方式实现此目标…
你可以…
使用JLabel,将标签的icon属性设置为图像的引用.然后,您可以将布局管理器应用于标签,并通过像往常一样简单地将其添加到标签中,将标签设置为其余组件的主要容器…
IconImage image = ...;
JLabel background = new JLabel(image);
background.setLayout(...);
// You could set the frames content pane to the label and keep
// working as per normal, adding components to the frame
setContentPane(background);
// or, simply add components to it directly like any other container
background.add(...);
这样做的好处是,如果GIF是动画的,它将包含正常播放的效果……很好的副作用.缺点是,JLabel不会为您调整图像的大小…
你可以…
将图像绘制到组件的背景(如JPanel),然后将剩余的组件添加到其中.
这将允许您应用特殊效果和/或调整图像大小(如果需要).但是,如果它是动画GIF,则它将变得极其复杂,因为您需要自己对帧进行动画处理.
看一眼…
更多细节