如何阻止JLabel.seticon不断重新绘制其他所有内容

时间:2015-02-27 07:32:32

标签: swing jlabel

我正在尝试将JInternalFrame名为GUIWindow.SpecialOptionsPopUp的{​​{1}}留在另一个JInternalFrame上,其中JLabel名为'标签'在里面。当标签不断更新其中的图像时,会发生此问题。

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JInternalFrame;
public class ForumQuestion extends JFrame {

    private JPanel contentPane;
    private JLabel label;
    private JInternalFrame internalFrame;
    private JInternalFrame internalFrame_1;
    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    ForumQuestion frame = new ForumQuestion();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public ForumQuestion() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        internalFrame_1 = new JInternalFrame("New JInternalFrame");
        internalFrame_1.setBounds(0, 0, 424, 250);
        contentPane.add(internalFrame_1);

        label = new JLabel("");
        internalFrame_1.getContentPane().add(label, BorderLayout.NORTH);
        internalFrame_1.setVisible(true);

        internalFrame = new JInternalFrame("New JInternalFrame");
        internalFrame.setBounds(145, 25, 171, 195);
        contentPane.add(internalFrame);
        internalFrame.setVisible(true);

        UpdateImage updateimage = new UpdateImage();
        updateimage.start();


    }

    private class UpdateImage extends Thread{

        public UpdateImage(){

        }
        public void run(){
            while(true){
                label.setIcon(new ImageIcon("C:/Users/Ali/EclipseWorkspace/ForumQuestion/testimage.png"));
                internalFrame.repaint();
                contentPane.setComponentZOrder(internalFrame, 0);
            }
        }
    }

}

0 个答案:

没有答案