私はこの "Javad" "label1"に画像 "Pic.png"を追加し、JFrame "window1"のJPanel "panel1"に表示しようとしています。しかし、私が走った時、それは私のイメージを表示しません。誰でも助けますか? (私はソースファイルに何かを追加することについて読んだが、私はJavaに慣れていないので何をしているのか分からない。イメージをラベルに追加しようとしましたが動作しませんか?
public class UIForIshidaQuery {
public static void main(String[] args) {
System.out.println("Running...");
JFrame window1 = new JFrame();
window1.setVisible(true);
window1.setSize(1080, 720);
window1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel1 = (JPanel) window1.getContentPane();
JLabel label1 = new JLabel();
panel1.setLayout(null);
ImageIcon image = new ImageIcon("C:\\Users\\BC03\\Pictures\\Saved Pictures\\Other\\Pic.png");
label1.setIcon(image);
label1.setBounds(500, 500, 500, 500);
panel1.add(label1);
}
}
新しいファイル( "C:\\ Users \\ BC03 \\ Pictures \ Saved Pictures \\その他\\ Pic.png")はexist() 'trueを返しますか? – Berger
[tag:embedded-resource]タグに引用されている例を参照してください(http://stackoverflow.com/tags/embedded-resource/info)。 – trashgod
はいそれはtrueを返します@Berger – Cutter