2

I was wondering if there is a quick and easy way of trying to position an image at a particular position in GUI. In addition to this is it possible to put Jlables/Buttons on this picture. That picture should only form a section of the JFrame. I know you can use setbounds(width, height, width, height); but this takes alot of accuracy and very hard to get perfectly right.

4

1 回答 1

3

不要调用setBounds,这意味着您正在使用null布局。始终使用布局管理器。

一种方法是添加一个JPanel覆盖paintComponent和调用的自定义drawImage(Image, x, y, width, height, ...)JLabels/JButtons等仍然可以添加到面板中。

不要忘记调用super.paintComponent——这将确保您的子组件被绘制。

另外,看看背景面板

于 2013-01-08T22:08:10.723 回答