http://www.javadrive.jp/tutorial/jlabel/index6.html
パスの指定でトラブル。
なぜか、
./hogehoge.pngでは駄目だけど
./img/hogehoge.pngでうまくいく。
validate
public void actionPerformed(ActionEvent e){ System.out.println("hogehoge"); JFileChooser filechooser = new JFileChooser(); int selected = filechooser.showOpenDialog(this); if (selected == JFileChooser.APPROVE_OPTION){ File file = filechooser.getSelectedFile(); if (checkBeforeReadfile(file)){ ImageIcon icon1 = new ImageIcon(file.getAbsolutePath()); JLabel label1 = new JLabel(icon1); p.add(label1); Container contentPane = getContentPane(); contentPane.add(p, BorderLayout.CENTER); contentPane.validate();//再描画 }else{ System.out.println("ファイルが見つからないか開けません"); } }
validateの他にrepaint?redraw?というのもあるらしい。