在用户拖动鼠标时收听 JFrame 调整事件大小?
2022-09-01 05:08:46
当用户单击 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");
}
}
如何确定和约束用户在围绕鼠标拖动时调整窗口大小的方式(基于窗口的当前纵横比)?