public void highlightThisText(){
int delay = 1000;
ActionListener tp = new ActionListener(){
public void actionPerformed(ActionEvent ae){
try{
System.out.println();
if(name.equals("Correct")){
thisPanel.getHighlighter().addHighlight(startIndex, endIndex, hl);
}
else{
anotherPanel.getHighlighter().addHighlight(startIndex, endIndex, hl);
}
} catch (BadLocationException ex) {
ex.printStackTrace();
}
}
};
Timer t = new Timer(delay, tp);
t.setRepeats(false);
t.start();
}
I need my program to enter into the highlightThisText method, executed the timer code, and after the delay leave the method. I understand that I cannot use Thread.sleep(1000); as this will block the EDT, but I cannot find any other examples on here with a similar problem. startIndex and endIndex will be incremented after the method is left which means the the correct line will not be highlighted.
Any help will be highly appreciated.