Como centralizar um JIternalFrame?(Resolvido)

Bom dia!!

Como centralizar um JIternalFrame??

Meu Código(JInternal Frame)

package br.com.fjsistemas.view;

import java.text.ParseException;

import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import javax.swing.text.MaskFormatter;

public class CadastroFuncionario extends JInternalFrame {

	private static final long serialVersionUID = 1585315595837755384L;
	private JTextField txtNome;
	private JTextField txtEndereco;
	private JTextField txtBairro;
	private JTextField txtNumero;
	private JTextField txtEmail;
	private JTextField txtCidade;

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public CadastroFuncionario() throws ParseException {

		setTitle("Cadastro de Funcionário");
		setClosable(true);
		setBounds(550, 100, 771, 480);

		JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "Dados Pessoais", TitledBorder.LEADING, TitledBorder.TOP, null, null));

		JButton btnNewButton = new JButton("Salvar");
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup().addContainerGap()
						.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(btnNewButton, Alignment.TRAILING)
								.addComponent(panel, GroupLayout.DEFAULT_SIZE, 735, Short.MAX_VALUE))
						.addContainerGap()));
		groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING,
				groupLayout.createSequentialGroup().addComponent(panel, GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE)
						.addGap(29).addComponent(btnNewButton).addContainerGap()));
		panel.setLayout(null);

		JLabel lblNome = new JLabel("Nome:");
		lblNome.setBounds(10, 36, 46, 14);
		panel.add(lblNome);

		txtNome = new JTextField();
		txtNome.setBounds(66, 33, 250, 20);
		panel.add(txtNome);
		txtNome.setColumns(10);

		JLabel lblDataNasc = new JLabel("Data Nascimento:");
		lblDataNasc.setBounds(356, 36, 100, 14);
		panel.add(lblDataNasc);

		JFormattedTextField fTxtDataNacimento = new JFormattedTextField(new MaskFormatter("##/##/####"));
		fTxtDataNacimento.setBounds(466, 33, 100, 20);
		panel.add(fTxtDataNacimento);

		JLabel lblCPF = new JLabel("CPF:");
		lblCPF.setBounds(10, 61, 46, 14);
		panel.add(lblCPF);

		JFormattedTextField fTxtCPF = new JFormattedTextField(new MaskFormatter("###.###.###-##"));
		fTxtCPF.setBounds(66, 58, 250, 20);
		panel.add(fTxtCPF);

		JLabel lblRG = new JLabel("RG:");
		lblRG.setBounds(356, 61, 46, 14);
		panel.add(lblRG);

		JFormattedTextField fTxtRG = new JFormattedTextField(new MaskFormatter("##.###.###-#"));
		fTxtRG.setBounds(400, 58, 166, 20);
		panel.add(fTxtRG);

		JLabel lblSexo = new JLabel("Sexo:");
		lblSexo.setBounds(602, 36, 46, 14);
		panel.add(lblSexo);

		JComboBox comboBoxSexo = new JComboBox();
		comboBoxSexo.setModel(new DefaultComboBoxModel(new String[] {"Selecione", "M", "F"}));
		comboBoxSexo.setBounds(642, 33, 71, 21);
		panel.add(comboBoxSexo);

		JLabel lblEndereco = new JLabel("Endereço:");
		lblEndereco.setBounds(10, 86, 55, 14);
		panel.add(lblEndereco);

		txtEndereco = new JTextField();
		txtEndereco.setBounds(66, 83, 250, 20);
		panel.add(txtEndereco);
		txtEndereco.setColumns(10);

		JLabel lblBairro = new JLabel("Bairro:");
		lblBairro.setBounds(356, 86, 46, 14);
		panel.add(lblBairro);

		txtBairro = new JTextField();
		txtBairro.setBounds(400, 83, 166, 20);
		panel.add(txtBairro);
		txtBairro.setColumns(10);

		JLabel lblNumero = new JLabel("Nº:");
		lblNumero.setBounds(602, 86, 46, 14);
		panel.add(lblNumero);

		txtNumero = new JTextField();
		txtNumero.setBounds(642, 83, 55, 20);
		panel.add(txtNumero);
		txtNumero.setColumns(10);

		JLabel lblCidade = new JLabel("Cidade:");
		lblCidade.setBounds(10, 111, 46, 14);
		panel.add(lblCidade);

		JLabel lblUF = new JLabel("UF:");
		lblUF.setBounds(602, 111, 46, 14);
		panel.add(lblUF);

		JComboBox comboBoxUf = new JComboBox();
		comboBoxUf.setModel(new DefaultComboBoxModel(new String[] {"Selecione", "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO"}));
		comboBoxUf.setBounds(642, 108, 71, 21);
		panel.add(comboBoxUf);

		JLabel lblFone = new JLabel("Fone:");
		lblFone.setBounds(10, 136, 46, 14);
		panel.add(lblFone);

		JFormattedTextField fTxtFone = new JFormattedTextField(new MaskFormatter("(##) ####-####"));
		fTxtFone.setBounds(66, 133, 250, 20);
		panel.add(fTxtFone);

		JLabel lblEmail = new JLabel("E-Mail:");
		lblEmail.setBounds(10, 161, 46, 14);
		panel.add(lblEmail);

		txtEmail = new JTextField();
		txtEmail.setBounds(66, 158, 250, 20);
		panel.add(txtEmail);
		txtEmail.setColumns(10);

		txtCidade = new JTextField();
		txtCidade.setBounds(66, 108, 250, 20);
		panel.add(txtCidade);
		txtCidade.setColumns(10);

		JLabel lblCelular = new JLabel("Celular:");
		lblCelular.setBounds(356, 136, 46, 14);
		panel.add(lblCelular);

		JFormattedTextField formattedTextField = new JFormattedTextField(new MaskFormatter("(##) #####-####"));
		formattedTextField.setBounds(400, 133, 166, 20);
		panel.add(formattedTextField);
		
		JLabel lblNewLabel = new JLabel("Estado:");
		lblNewLabel.setBounds(356, 111, 46, 14);
		panel.add(lblNewLabel);
		
		JComboBox comboBox = new JComboBox();
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"Selecione", "Acre", "Alagoas", "Amap\u00E1", "Amazonas", "Bahia", "Cear\u00E1", "Distrito Federal", "Espir\u00EDto Santo", "Goi\u00E1s", "Maranh\u00E3o", "Mato Grosso", "Mato Grosso do Sul", "Minas Gerais", "Par\u00E1", "Para\u00EDba", "Paran\u00E1", "Pernanbuco", "Piau\u00ED", "Rio de Janeiro", "Rio Grande do Norte", "Rio Grande do Sul", "Rond\u00F4nia", "Roraima", "Santa Catarina", "S\u00E3o Paulo", "Sergipe", "Tocantins"}));
		comboBox.setBounds(400, 107, 166, 22);
		panel.add(comboBox);
		getContentPane().setLayout(groupLayout);

	}
}

Cria o seguinte método no seu CadastroFuncionario:

public void centralizar() {
    Dimension thisSize = getSize();
    Dimension deskSize = getDesktopPane().getSize();
    int x =  (deskSize.width - thisSize.width)  / 2;
    int y = (deskSize.height - thisSize.height) / 2;
    setLocation(x, y);
}
1 curtida