Search code examples
javaswingtimerjframebounds

problem with getting JFrame bounds inside a timer in Netbeans


I want to animate a JFrame to become half-size when i press a button in my programme. I think the easiest way is putting the current bounds of JFrame into a timer and decrease bounds 1 by 1 when the timer running.But when I declare a new timer in netbeans IDE it will looks like this.

      Timer t = new Timer(5,new ActionListener() {

        public void actionPerformed(ActionEvent e) {

          //inside this I want to get my Jframe's bounds like this
           //    int width = this.getWidth();---------here,"this" means the Jframe

           }

        }
    });

But the problem is in here "this" not refering to JFrame.And also I cant even create a new object of my JFrame.Because it will give me another window.Can anyone help me solve this problem ?.


Solution

  • Try

    int width = Foo.this.getWidth();
    

    where Foo subclasses JFrame.