我收到了这段代码:
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)时,它永远不会工作。我认为这是因为这种布局。所以我的问题是,如何在我的框架中设置背景图像?
寻求帮助
答案 0 :(得分:3)
答案 1 :(得分:1)
关注链接可能有所帮助。见接受的答案: