Posicionamento/Alinhamento de Componentes Swing

3 respostas
A

Olá pessoal, estou com problemas em relação a posicionamento e alinhamento de componentes do pacote swing!

Tenho uma classe que está da seguinte forma:

import javax.swing.JInternalFrame;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;

import java.awt.FlowLayout;



public class PacienteInterface extends JInternalFrame {
	
	private JPanel jpcad = new JPanel();
	private JTextField tf_nome = new JTextField(50);
	private MeuappPrincipal princip;
	
	public PacienteInterface(MeuappPrincipal jframe){
		
		super("Pacientes",true,true,true,true);
		
		
		
		princip = jframe;

		JLabel lb_nome = new JLabel("Nome");
		jpcad.add(lb_nome);	
		jpcad.add(tf_nome);
		jpcad.setBorder(new TitledBorder("Cadastro e Consulta de Pacientes"));
		//jpcad.setSize(this.getWidth(),this.getHeight());
		getContentPane().add(jpcad);
		
		
		
		
	}

}

Tentei alinhar de diversas formas e entao cansei…

Como eu posso jogar esses 2 componentes (label e text) pro meu canto esquerdo?

Obrigado :slight_smile:

3 Respostas

A

Olá,

Você já leu isto aqui?

http://www.guj.com.br/java.tutorial.artigo.38.1.guj

Abraços.

A

Cara, ja havia lido isso mas mesmo assim não to conseguindo fazer exatamente o q eu quero…

veja um “desenho” do q eu quero fazer:

+----------------------------------------------------------------------+
| JInternalFrame                                                                   |
+----------------------------------------------------------------------+
|  LabelNome                                                                       
|  TxFieldNome                                                                    
|  LabelIdade
|  TxFieldIdade
|  //OUTROS CAMPOS NO MESMO ESQUEMA
|
|  [BotãoADD] [BotaoLimpar]
|
|   +-------------------------------------------------------------+
|   | GRID DE CADASTROS                                             |
|   +-------------------------------------------------------------+
|   |                                                                              |
|   |                                                                              |
|   |                                                                              |
|   |                                                                              |
|   +-------------------------------------------------------------+
|
+---------------------------------------------------------------------------+

é basicamente assim!

Mas ta dificil viu…

Alguma ideia?

E eu tenho q fazer na mão mesmo

R

Fala,

De acordo com seu objetivo eu utilizaria o GridLayout ou GridBagLayout.
Esta apostila é bem legal:
http://www.inf.puc-rio.br/~java/progjava/protected/apostilas/GUI.pdf

Tem alguns exemplos da Sun:

http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html
http://java.sun.com/docs/books/tutorial/uiswing/layout/grid.html

Sucessos.

Criado 2 de novembro de 2007
Ultima resposta 4 de nov. de 2007
Respostas 3
Participantes 3