我得到一个 JFrame,我想显示一个带有边框的 JLabel,其中填充可能为 50px。当我将 JFrame 的大小设置为 750、750 并将 JLabel 的大小设置为 650、650 并将位置设置为 50、50 时,它显示它很奇怪......这是我的代码:
public class GUI {
/**
* Declarate all
*/
public int height = 750;
public int width = 750;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width / 2) - (width / 2); // Center horizontally.
int y = (screen.height / 2) - (height / 2); // Center vertically.
/**
* Create the GUI
*/
JFrame frame = new JFrame();
Border border = LineBorder.createBlackLineBorder();
JLabel label = new JLabel();
public GUI(){
label.setBorder(border);
label.setSize(700, 700);
label.setLocation(0, 0);
frame.getContentPane().setLayout(null);
frame.add(label);
}
public void createGUI() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(x,y,width,height);
frame.setVisible(true);
}
}
所以我认为顶部的标题栏也包含在大小中。在图形中,您可以使用getInsets()
. Swing / JFrame 现在有类似的东西吗?