Obtém o tamanho real de um conteúdo JFrame
Eu recebo um JFrame e quero exibir um JLabel com uma borda nele com um preenchimento de talvez 50px. Quando eu definir o tamanho do JFrame para 750, 750, e o tamanho do JLabel para 650, 650 e a localização para 50, 50, ele mostra estranho ... Aqui está o meu 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);
}
}
Então eu acho que a barra de título no topo também está incluída no tamanho. Em gráficos, você pode usargetInsets()
. Agora há algo parecido com o Swing / JFrame?