Nem sempre fica com a mesmo formato

Olá,

Criei o código fonte abaixo, mas nem sempre os componentes ficam na posição indicada pelo setBounds.

import javax.swing.;
import java.awt.
;

public class Swing12 extends JFrame {

Container form;

String[]lista_Estados = {"AM", "RS", "PI", "MA",};

public void Monta_Form(){
  form = new JFrame("Meu 11º Form");
  form.setLocation(10,10);
  form.setSize(800,600);
  form.setVisible(true);
		
  JLabel rotulo1 = new JLabel("Nome:"); 
  form.add(rotulo1); 
  rotulo1.setBounds(10,5,200,20);
		
  JTextField nome = new JTextField(10);
  form.add(nome);
  nome.setBounds(80,5,100,20);
		
  JButton botao = new JButton("OK");
  form.add(botao);
  botao.setBounds(80,30,100,20);
  
  CheckboxGroup sexo = new CheckboxGroup();
  Checkbox sexo1 = new Checkbox("Masculino",sexo,false);
  Checkbox sexo2 = new Checkbox("Feminino",sexo,true);
  form.add(sexo1);
  form.add(sexo2);
  sexo1.setBounds(80,50,100,20);
  sexo2.setBounds(80,70,100,20);

  Checkbox ingles   = new Checkbox("Inglês",false);
  Checkbox espanhol = new Checkbox("Espanhol",false);
  form.add(ingles);
  form.add(espanhol);
  ingles.setBounds(80,90,100,20);
  espanhol.setBounds(80,110,100,20);
  
  JList estados = new JList(lista_Estados);
  form.add(estados); 
  estados.setBounds(90,160,50,100);
  
  JTextArea memo = new JTextArea();
  form.add(memo);
  memo.setBounds(180,160,100, 90);
}
public static void main(String[] args) {
  new Swing12().Monta_Form();

}
}

E ai…

Tu esta usando 2 JFrame, um no ‘extends JFrame’ e outro no form.
Mas soh precisa de um JFrame. O teu formulario em si, faz em um JPanel e depois adiciona
ele no teu JFrame!

Para testes, eu uso essa estrutura aqui

public class MyForm extends JPanel {

	// nessa classe tu cria o teu formulario
	
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.setContentPane(new MyForm());
		frame.setSize(800, 600);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
}

Entendeu?

public class Swing15 extends JPanel {

  JLabel rotulo1 = new JLabel("Nome:"); 
  JPanel.add(rotulo1); 
      rotulo1.setBounds(10,5,200,20);
		
  JTextField nome = new JTextField(10);
  JPanel.add(nome);
  nome.setBounds(80,5,100,20);

public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setContentPane(new Swing15());
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

public class Swing15 extends JPanel {

  JLabel rotulo1 = new JLabel("Nome:"); 
  JPanel.add(rotulo1); 
      rotulo1.setBounds(10,5,200,20);
		
  JTextField nome = new JTextField(10);
  JPanel.add(nome);
  nome.setBounds(80,5,100,20);

public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setContentPane(new Swing15());
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

public class Swing15 extends JPanel {

  JLabel rotulo1 = new JLabel("Nome:"); 
  JPanel.add(rotulo1); 
      rotulo1.setBounds(10,5,200,20);
		
  JTextField nome = new JTextField(10);
  JPanel.add(nome);
  nome.setBounds(80,5,100,20);

public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setContentPane(new Swing15());
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

rsa_tche, te aconselho a ler alguns tutoriais basico de java por ai, pra aprender a linguagem…

Pois esse exemplo que tu postou tem uns codigos soltos no meio da classe… Isso nao pode…

Bom, sobre a tela, para definir posicoes tu tem que passar null no layout…
Melhor colocar um exemplo bem simples

public class MyForm extends JPanel {

	public MyForm() {
		this.setLayout(null);
		JTextField field = new JTextField();
		field.setBounds(10, 10, 200, 22);
		this.add(field);

		JButton button = new JButton("Cancel");
		button.setBounds(10, 42, 200, 22);
		this.add(button);
	}

	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.setContentPane(new MyForm());
		frame.setSize(800, 600);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
}