0
我有一個簡單的應用程序與一個JPanel和一個計時器,打算每個框架打印面板的大小和位置。JPanel.getBounds不更新
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class GetBoundsTest extends JPanel {
public GetBoundsTest() {
setSize(100, 100);
Timer t = new Timer(40, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(GetBoundsTest.this.getBounds());
}
});
t.start();
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.add(new GetBoundsTest());
f.setVisible(true);
f.setBounds(new Rectangle(50, 50, 50, 50));
}
}
我遇到的問題是當窗口移動時邊界不更新。
的邊界。所以如果JPanel沒有相對於它的容器移動,那麼它的邊界不會改變。 – 2014-09-10 21:07:55