JProgressBar in JTable problem

纵然是瞬间 提交于 2020-01-04 06:35:35

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/7239410/jprogressbar-in-jtable-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!