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

How to use Java to navigate a Web Search
How I get the scheduler Jobs in Java EE server
Unique constraint with JPA and Bean Validation
How do I create a breakpoint at a specific place without there being any code after it
Spring and synchronization for part of the method
Java starting a thread pool in objects constructor
Is there a declarative way to parse XML to Java objects?
Lock or synchronized
jButtons resize on runtime
Creating a cross platform installer in Linux
Deserialization of arrays of custom type in OSGi
question in designing a class in java
Tomcat in Production [closed]
OutOfMemory Error java heap space
How to build a SOAP Web service Client in SEAM
Memory leaks with HashMap/HashSet on Android

Categories

HOME
bluetooth
gerrit
webpack
urbancode
push-notification
raspberry-pi
filtering
win32gui
ojdbc
acquia
uber-api
swagger-ui
metatrader4
spring-xd
zend-framework3
windows-phone-7
openrefine
propel
ml
numerical-methods
fgetcsv
fluentvalidation
opentype
c++-amp
bcd
mapbox-gl
vxworks
swisscomdev
withings
webix-treetable
uft-api
user-controls
fedex
midl
vao
total-commander
logfiles
google-datalayer
user-accounts
datastax-startup
worker-thread
qtwebview
akka-cluster
titanium-android
query-performance
cubes
url-pattern
dstu2-fhir
thrust
lttng
sigabrt
skype4py
wapiti
pyke
retina
atk4
wireshark-dissector
citrus-pay
0xdbe
composite
p2
sonarqube5.1.2
nsmutabledictionary
jsonpickle
nstableviewcell
cctv
rdtsc
php-5.4
expected-exception
datagridviewcolumn
hyprlinkr
didselectrowatindexpath
oam
jsctypes
access-rights
web2py-modules
ril
pushbackinputstream
jelly
kyotocabinet
jspinclude
ohm
punbb
nsdatecomponents
gnustep
external-accessory
genshi
self-extracting
blitz++
sector
genealogy
wsdl.exe
rtml

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