java


Fire only the last event in a series of events in JavaFX


I have a PackingCanvas that draws elements on the screen, which is an extension of the JavaFX Canvas control. I want my elements to be drawn on resize, but only when the resize is done, as redrawing the entire canvas on every resize event might be too costly in some situations.
What I have now is the following:
widthProperty().addListener(evt -> draw());
heightProperty().addListener(evt -> draw());
I have tried doing this with threads; add a small delay, see if new a new thread is created, if not; draw(), else abort current thread.
However, this doesn't seem like an elegant solution to me. Is there an idiom to deal with these problems?
you can cache width & height inside draw() function.
void draw()
{
cacheHeight = getHeight();
cacheWidth = getWidth();
}
then
heightProperty().addListener(evt -> {if(getHeight()!=cacheHeight) draw();});

Related Links

Spring Authentication Required ERROR [duplicate]
Android Product Flavors for Java Web Projects
[Java][SQL] Hardcoded username and password on query
how to modify the value of a primitive data passed to a C++ routine using Java and JNI?
Java: test System output including “new lines” with assertEquals
How to ignore ' ' in Xpath?
Casting a type in a data structure
Spring Boot EnableCaching and Cacheable annotation not working
FATAL EXCEPTION: main NoSuchMethodError for VideoView.setOnPreparedListener() [duplicate]
Using SWIG to wrap c++ to java UnsatisfiedLinkError: HeaderJNI.new_Test()J
Java accessing object throught array
JavaFX ScrollPane setVvalue() not working as intended
Efficient handling of mouse clicks
Right syntax for concat on derby
Break 2 loops if condition satisfied in Java [duplicate]
Simple Java currency converter errors

Categories

HOME
multithreading
testng
coq
react-virtualized
onedrive
fft
mvvmcross
convolution
azure-storage-tables
constraint-programming
cross-validation
size
dosgi
seaborn
invantive-sql
django-cms
amazonsellercentral
autocad-plugin
zapier
dcevm
telerik-reporting
smb
microsoft-sync-framework
su
maquette
elasticsearch-net
preg-match-all
xquery-3.0
language-concepts
google-api-nodejs-client
hot-module-replacement
ansible-playbook
lumberjack
cookiecutter-django
dism
email-templates
nand2tetris
heightmap
auto-update
angular-resource
theming
domain-model
return-value
magma
mcafee
pycaffe
objective-c-swift-bridge
adxstudio-portals
paypal-express
angstrom-linux
packagist
goose
revolution-r
wapiti
associative-array
phpcas
browser-link
freelancer.com-api
unity-networking
cannon.js
wyam
system32
lustre
formatjs
rake-task
network-interface
android-imagebutton
neolane
srs
mcts
ms-project-server-2010
tws
pygit2
limejs
trusted
errai
ohm
netdna-api
locationlistener
locate
mongomapper
bespin
sef
mediarss

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App