JTable中的JProgressBar问题 [英] JProgressBar in JTable problem

查看:59
本文介绍了JTable中的JProgressBar问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了问题,有人可以帮助我吗? 下面是我的代码:

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);
    }     
} 

我的问题是这些jprogressbars如何插入表的单元格中?

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

推荐答案

您将必须创建自己的TableCellRenderer

You will have to create you own TableCellRenderer

在该TableCellRenderer中,您将不得不用JProgressBar替换标准标签

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

表格的基础: http://download.oracle.com/javase/tutorial/uiswing/components/table.html

这篇关于JTable中的JProgressBar问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆