问题
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