I'm trying to make the JFrame re-meaningful in an unusual way: the ratio of width to frame height should be constant. I wrote this simple code; in this case, the ratio is 1/2:
public class Panel extends JFrame { public Panel() { addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { System.out.println("Reseized"); setSize(getSize().width, getSize().width * 2); } }); }
But this frame has problems with redrawing, and it only works when the user drags the mouse. When the drag and drop is completed, the lower right corner of the frame is at the point where the user released the mouse.
Maybe the componentResized method is not applicable in this case? So what should I use? Thanks in advance.
source share