JTable中的JProgressBar问题
我有一些问题,有人可以帮助我吗? 下面是我的代码:
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 如何插入表格的单元格中?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将必须创建自己的 TableCellRenderer
在该 TableCellRenderer 中,您将必须用 JProgressBar 替换标准标签
然后您将必须维护一些逻辑来跟踪您的进度并在进度推进时刷新您的表格
表格的基础知识: http://download.oracle.com/javase/tutorial/uiswing/components/table.html
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