4
如何在JScrollPane中添加圖像作爲背景? 我試過,但圖像不顯示:圖像作爲JScrollPane中的背景
BufferedImage img = null;
try {
img = ImageIO.read(new File("C:\\Users\\Suraj\\Documents\\NetBeansProjects\\JavaApplication2\\src\\javaapplication2\\images\\2.jpg"));
}
catch (IOException e) {
e.printStackTrace();
}
Image imag = img.getScaledInstance(d.width, d.height, Image.SCALE_SMOOTH);
ImageIcon imageBack = new ImageIcon(imag);
FlowLayout fl = new FlowLayout();
frame.getContentPane().setLayout(fl);
fl.addLayoutComponent(null, new JLabel(imageBack));
編輯:我想補充的JLabel和Jbuttons中的JScrollPane中與背景
如果我不得不添加其他對象,如按鈕怎麼辦?....我該怎麼做? – user3188978
@ user3188978:請參閱編輯以回答。 –