我試圖在用BoxLayout格式化的JPanel中放置一個簡單的圖標。當我嘗試在Java中放置ImageIcon時出錯
JPanel panel_4 = new JPanel();
contentPane.add(panel_4, BorderLayout.CENTER);
panel_4.setLayout(new BoxLayout(panel_4, BoxLayout.X_AXIS));
ImageIcon seven= new ImageIcon("C:\\Users\\alewe\\workspace\\SlotMachine\\Lucky_Seven-128.png");
JLabel lblNewLabel_1 = new JLabel(seven);
panel_4.add(lblNewLabel_1);
當我運行它給我的錯誤「Some characters cannot be mapped using "Cp1252" character encoding
」的代碼,我救了UTF-8
,現在它開始,但我不能看到圖標。
[這](http://stackoverflow.com/questions/1242581/display-a-jpg-image-on-a-jpanel)可能會幫助 –