How to bind jlabel with arraylist size?
I am showing arraylist size in a JLabel. What I want is whenever the size of arraylist changes it should reflect in JLabel. Can i开发者_运维问答t be done? Can I bind arraylist size to JLabel? I don't want to manually do this by jLabel.setText(arrList.size());
every time.
There's no support in Java for binding a UI component to a data structure as you can in other languages like ActionScript. You could set up a timer that will ask the ArrayList
how big it is and then set the text of the JLabel
accordingly. You'd probably need to do this in a background thread as you wouldn't want to hold the main thread while your timer loops infinitely.
精彩评论