当用户单击JFrame的角落以调整大小并拖动鼠标时,JFrame将根据用户拖动的鼠标的当前位置重新绘制。你怎么能听这些事件?在用户拖动鼠标时收听JFrame调整大小事件?
下面是我所目前正在尝试:
public final class TestFrame extends JFrame {
public TestFrame() {
this.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
// This is only called when the user releases the mouse button.
System.out.println("componentResized");
}
});
}
// These methods do not appear to be called at all when a JFrame
// is being resized.
@Override
public void setSize(int width, int height) {
System.out.println("setSize");
}
@Override
public void setBounds(Rectangle r) {
System.out.println("setBounds A");
}
@Override
public void setBounds(int x, int y, int width, int height) {
System.out.println("setBounds B");
}
}
如何确定并限制用户如何调整其大小的窗口(基于窗口的当前长宽比),因为他们周围拖动鼠标周围?
@finnw请你澄清你的赏金理由,因为我看到'Java_1.4'和'Java_1.5'之间的区别,但是我找不到'Java_6','note'的区别,但是没有最深的检查到嵌套和继承方法 – mKorbel 2011-10-06 08:53:39
@mKorbel,我尝试了两种方法(JPanel上的ComponentListener;覆盖验证)。代码编译并在两个版本的Java下运行,但在Java 1.6中,布局不断被重新计算,但是在Java 1.5只有当我释放鼠标。 – finnw 2011-10-06 12:17:35
@finnw你调整JComponent或JFrame – mKorbel 2011-10-06 12:23:40