Mein aktueller Code sieht etwa so aus:
Code: Select all
private JLabel lError;
.....
private void updateLabel (String text)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
lError.setText(text);
}
});
lError.repaint();
}
.....
bFind.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
{
Thread t1 = new Thread(new Runnable()
{
@Override
public void run()
{
myLongProcessingTask()
}
});
duplicates.clear();
try
{
t1.start();
lError.setText(""); // set it at the end of processing
}
catch (Exception err){}
// Do this after processing
selectedIndex = -1;
nextDuplicate();
}
});
.....
private void myLongProcessingTask()
{
// Do something really heavy in a loop
// Every loop iteration call this:
updateLabel("Some text" + i); // basically a progress tracking label
}
Ich habe versucht, t1.join() davor hinzuzufügen, aber dann hängt die Schnittstelle, als ob ich keinen Thread verwendet hätte, und die Bezeichnung wird auch nicht aktualisiert.
Ich bin nicht sehr gut mit Java. Wie löse ich das?
Mobile version