我有一个关于如何使两个JFrame大小相同的问题。当用户调整一侧的尺寸时,另一侧的尺寸也将得到调整,然后再调整尺寸(与数字一相同)。谢谢您的帮助。
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DrawingPanel panel = new DrawingPanel();
frame.setPreferredSize(new Dimension(windowWidth, windowHeight));
frame.setMinimumSize(new Dimension(windowWidth, windowHeight));
frame.setLocationRelativeTo(null);
//resize both size at the same number
int height = windowHeight;
int widht = windowWidth;
frame.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent evt) {
if (frame.getHeight() > windowHeight) {
frame.setSize(new Dimension(frame.getHeight(), frame.getHeight()));
frame.pack();
}
if (frame.getWidth() > windowWidth) {
frame.setSize(newDimension(frame.getWidth(), frame.getWidth()));
}
}
});
frame.add(panel);
frame.pack();
frame.setVisible(true);