Java – detects when the user has finished resizing the SWT shell
•
Java
I have a resizable SWT shell Every time I resize, I have to do something computationally intensive
I can register a controllistener on my shell, but this will continuously generate events throughout the resizing operation. I don't know when the resizing drag type mouse operation ends
I want to be able to detect when the user resizes the shell and then start my compute intensive operations Any idea how to do it?
Solution
Use a timer and start the operation after a delay of one second after the last resizing event is received?
long lastEvent; ActionListener taskPerformer = new ActionListener() { public void doCalc(ActionEvent evt) { if ( (lastEvent + 1000) < System.currentTimeMillis() ) { hardcoreCalculationTask(); } else { // this can be timed better new Timer(1000,taskPerformer).start(); } } }; }
In your resize event:
lastEvent = System.currentTimeMillis(); new Timer(1000,taskPerformer).start();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码