开发者

JProgressBar in JTable problem

I've got some problem, does anyone can help me ? Below is my code:

public class Test
{   
    public static void main(String[] args) 
    {
      Panel.panel.setVisible(true);
    }

}

class Panel extends JFrame implements Runnable
{
    public static Panel panel = new Panel();

    JButton b= new  JButton("Start");

    public Panel()
    {
        setLayout(new FlowLayout());    
        setSize(300,300);       
        add(b);

        b.addActionListener(new ActionListener()
        {           
            public void actionPerformed(ActionEvent e) 
            {
                javax.swing.SwingUtilities.invokeLater(new Runnable()
                {                   
                    public void run() 
                    {
                       Thread t = new Thread(Panel.panel);
                       t.start();
                    }
                });
            }                   
        });
    }

    public void doSomething(int start, int end)
    {
        JProgressBar bar = new JProgressBar(start, end);
        Panel.panel.add(bar);
        bar.setStringPainted(true);

        try
        {
            for(int i = start; i<=end;i++)
            {
                bar.setValue(i);                    
                Thread.sleep(200);  
                if(bar.getValue() == end)
         开发者_开发技巧           bar.setString("END");
            }

        } catch (InterruptedException e) 
        {               
            e.printStackTrace();
        }      
    }

    public void run() 
    {
        doSomething(0, 50);
    }     
} 

My question is how these jprogressbars insert in table's cells ?


You will have to create you own TableCellRenderer

In that TableCellRenderer you will have to replace the standard label with a JProgressBar

Then you will have to maintain some logic to keep track of your progress and refresh your table as your progress advances

basics of table: http://download.oracle.com/javase/tutorial/uiswing/components/table.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜