当前位置: 代码迷 >> J2SE >> 求解零 0关于swing JFrame 里面的remove和add函数
  详细解决方案

求解零 0关于swing JFrame 里面的remove和add函数

热度:3108   发布时间:2013-02-25 00:00:00.0
求解0 0关于swing JFrame 里面的remove和add函数
Java code
 ImageIcon image = new ImageIcon("C:\\myworkspace\\catchhtmlpic\\google.png");            this.getContentPane().remove(img1);            img1 = new JLabel(image);// put pic in img1。            add(img1, BorderLayout.CENTER);            this.pack();


就是这一段,我的图片是动态生成的,所以图片位置一样,我这里想2次打开同样位置上的图片,在remove()之后做add()他还是现实之前的那一张图片,而如果我把图片改个名就能显示出来
Java code
            ImageIcon image = null;            if(loadpicFlag)                image = new ImageIcon("C:\\myworkspace\\catchhtmlpic\\google.png");            else                image = new ImageIcon("C:\\myworkspace\\catchhtmlpic\\aaaaa.png");            loadpicFlag = !loadpicFlag;            this.getContentPane().remove(img1);            img1 = new JLabel(image);// put pic in img1。            add(img1, BorderLayout.CENTER);            this.pack();

像这样。。。是因为java的优化么。。求问怎么在不改文件名的情况下显示图片QAQ

------解决方案--------------------------------------------------------
image.getImage().flush();