【发布时间】:2013-10-04 15:00:47
【问题描述】:
我得到了这个代码:
JFrame frame = new JFrame("FilesComparator");
frame.setVisible(true);
frame.setSize(1000, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation(dim.width / 2 - frame.getSize().width / 2, dim.height
/ 2 - frame.getSize().height / 2);
JButton buttonStart;
JButton buttonCancel;
pane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
buttonStart = new JButton("Start");
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 1.0;
c.anchor = GridBagConstraints.PAGE_END;
buttonStart.addActionListener(new ActionStart());
pane.add(buttonStart, c);
buttonCancel = new JButton("Cancel");
c.fill = GridBagConstraints.HORIZONTAL;
c.weighty = 15.0;
c.anchor = GridBagConstraints.PAGE_END;
buttonCancel.addActionListener(new ActionCancel());
pane.add(buttonCancel, c);
}}
一切正常。但是当我想添加图像背景(image.jpeg)时,它永远不会起作用。我想是因为这个布局。所以我的问题是,如何为我的框架设置背景图像?
谢谢帮助
【问题讨论】:
-
希望answer 能够在这方面为您提供帮助。再发一封detailed answer 了解更多信息。第二个example,在这个链接上也有助于这个方向:-)
-
@nIcEcOw 感谢这个,它就像一个字符 :) 如果你的评论是一个答案,我会接受这个。
-
很高兴,它对您有所帮助。我希望我可以将其作为答案发布,但这会导致论坛上的冗余,这被认为是一种不好的做法 :-) 尽管对于其余的人来说,你最欢迎并保持微笑:-)