当用户单击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");
}
}
当用户围绕鼠标拖动时,如何确定和约束用户如何调整窗口大小(基于窗口的当前纵横比)?
最佳答案
You probably need to override something like validate
(don't forget to call the super). Of course, that still may not work if you are using a windowing system to configured to drag outlines.