Obtenga el tamaño real de un contenido de JFrame
Obtengo un JFrame y quiero mostrar una JLabel con un borde en ella con un relleno de quizás 50px. Cuando configuro el tamaño del JFrame en 750, 750, y el tamaño de la JLabel en 650, 650 y la ubicación en 50, 50, se ve extraño ... Aquí está mi código:
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);
}
}
Así que creo que la barra de título en la parte superior también se incluye en el tamaño. En Gráficos puedes usargetInsets()
. Ahora, ¿hay algo así para Swing / JFrame?