Matheus, experimente:
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.*;
public class JanelaCentrada {
public static void main(String args[]) {
JFrame frame = new JFrame();
JButton bot = new JButton("Estou Centrado!");
//O GridBagLayout é muito complicado, mas o default dele é centrar...
GridBagConstraints constr = new GridBagConstraints();
frame.getContentPane().setLayout(new GridBagLayout());
frame.getContentPane().add(bot, constr);
frame.setBounds(100,100,300,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Tem muita solução disponível na web. Essa aí eu me inspirei colocando as
palavras chave seguintes no Google: "how to center a component" swing
abraços,
Jonathan
2011/7/1 Matheus Henrique Klem Galvez <[email protected]>
> Qual o melhor layoult para centralizar um objeto exatamente no centro
> do container (tanto vertical como horizontalmente). Não estou
> conseguindo este efeito com os layoults padrão.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Comp 2 - Geral" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/comp2-geral?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "Comp
2 - Geral" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/comp2-geral?hl=en.