所以我正在尝试将图像添加到我的JFrame中,我正在使用BorderLayout.PAGE_START,但我不想要灰色背景。有没有办法“删除”该背景或使用其他布局执行此操作并获得我想要的结果?
*我还要在画面底部添加一些图像,所以我也不想在那里有灰色背景。
编辑:这是我的代码:
private JFrame getCreatedFrame(){
JFrame frame = new JFrame("test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(screenSize);
frame.setLocationRelativeTo(null);
JFrame.setDefaultLookAndFeelDecorated(true);
//set icon image
String imgName = "images/domino.png";
URL imageURL = getClass().getResource(imgName);
if (imageURL != null) {
icon = new ImageIcon(imageURL);
}
frame.setIconImage(icon.getImage());
//set background image
imgName = "images/background.jpg";
imageURL = getClass().getResource(imgName);
if (imageURL != null) {
icon = new ImageIcon(imageURL);
}
JLabel background=new JLabel(icon);
frame.add(background);
return frame;
}
public void start() {
short version=0,choice=0;
JFrame frame=getCreatedFrame();
//set welcome image
String imgName = "images/welcome.png";
URL imageURL = getClass().getResource(imgName);
if (imageURL != null) {
icon = new ImageIcon(imageURL);
}
JLabel welcome=new JLabel(icon);
frame.add(welcome,BorderLayout.PAGE_START);
frame.setVisible(true);
}
建议:
例如,类似于:
paintComponent(...)