Formulario Bagunçado

5 respostas
tiago466

Ola Pessoal

Eu criei um formulario com o seguinte codigo:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Cadastro extends JFrame implements ItemListener{
	
	JLabel L1;
	JLabel L2;
	JLabel L3;
	JLabel L4;
	JLabel L5;
	JTextField T1;
	JTextField T2;
	JTextField T3;
	JTextField T4;
	JButton B1;
	JButton B2;
	JButton B3;
	
	public Cadastro(){
		this.setResizable(false);
		this.setTitle("Cadastro de Clientes");
		this.setSize(400,400);
		this.setLayout(new FlowLayout());
		
		L1 = new JLabel("Cadastro");
		L1.setForeground(new java.awt.Color(51, 0, 255));
		L1.setFont(new java.awt.Font("Monotype Corsiva", 1, 36));
		
		L2 = new JLabel("Codigo");
		L2.setForeground(new java.awt.Color(51, 153, 255));
		T1 = new JTextField(10);
		
		L3 = new JLabel("Nome");
		L3.setForeground(new java.awt.Color(51, 153, 255));
		T2 = new JTextField(20);
		
		L4 = new JLabel("Sobrenome");
		L4.setForeground(new java.awt.Color(51, 153, 255));
		T3 = new JTextField(20);
		
		L5 = new JLabel("Telefone");
		L5.setForeground(new java.awt.Color(51, 153, 255));
		T4 = new JTextField(20);
		
		B1 = new JButton("Cadastrar");
		B2 = new JButton("Limpar");
		B3 = new JButton("Fechar");
		
		this.add(L1);
		this.add(L2);
		this.add(L3);
		this.add(L4);
		this.add(L5);
		this.add(T1);
		this.add(T2);
		this.add(T3);
		this.add(T4);
		this.add(B1);
		this.add(B2);
		this.add(B3);		
	}
	public static void main(String args[]){
		JFrame janela = new Cadastro();
		janela.setDefaultCloseOperation(EXIT_ON_CLOSE);
		janela.setLocationRelativeTo(null);
		janela.setVisible(true);
	}
	
}

Mas so que ele eta todo bagunçado.
Como eu faço para organiza-lo?

Grato

5 Respostas

D

Cara… não sou muito bom com Swing (minha praia é WEB =]), mas já tentou usar null layout?! Talvez funcione melhor com este esquema de posicionamento por pixels.

Espero ter ajudado. Até.

M

Opa, beleza?Procure por layout managers!

tiago466

Mas onde eu acho esse layout managers?

Ironlynx

Veja em:
http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html
e
http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html

tiago466

Ironlynx:
Veja em:
http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html
e
http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html

brigadao cara ate mais

Criado 1 de outubro de 2007
Ultima resposta 1 de out. de 2007
Respostas 5
Participantes 4