我正在尝试使用 Eclipse 创建一个 Java 7 地址簿,当我测试运行 JFrame 时,JLabel 不可见并且 JButton 重叠。 (按钮将占据整个 JFrame) 例如
add(saveButton);
add(cancelButton);
add(headingLabel);
headingLabel.setVisible(true);
cancelButton.setLocation(200,200);
saveButton.setLocation(400,200);
cancelButton.setSize(200,50);
saveButton.setSize(200,50);
我做错了什么?
最佳答案
您应该使用 LayoutManager 而不是绝对坐标。使用布局管理器,您不必太在意 GUI 元素的确切位置。布局已为您完成。
查看 Visual Guide to Layout Managers.它通过视觉和代码示例解释了最常见的布局类型。
关于java - 如何防止 GUI 在 Java 中重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14388363/