oilujaguiar 13 de nov. de 2012
Desculpe, mas não seria o
nome.setBounds (50,50,50,50);
Abraço
queroaprender 13 de nov. de 2012
set bounds não deu, vou postar código inteiro, mas fica todo bagunçado hora da impressão
package Interface ;
import java.awt.BorderLayout ;
import javax.swing.JButton ;
import javax.swing.JFrame ;
import javax.swing.JLabel ;
import javax.swing.JPanel ;
import javax.swing.JTextField ;
public class Janela_Cadastra_Cliente extends JFrame {
public Janela_Cadastra_Cliente () {
initComponents ();
}
private void initComponents () {
JFrame cadastracliente = new JFrame ( "Cadastro de Cliente" );
cadastracliente . setSize ( 550 , 500 );
cadastracliente . setVisible ( true );
JPanel CadastroCli = new JPanel ();
JLabel nome = new JLabel ();
nome . setText ( "Nome : " );
CadastroCli . add ( nome );
JTextField text_nome = new JTextField ( 40 ) ;
CadastroCli . add ( text_nome );
text_nome . setBounds ( 150 , 50 , 50 , 50 );
JLabel dtnasci = new JLabel ();
dtnasci . setText ( "Data de Nascimento: " );
CadastroCli . add ( dtnasci );
JTextField datanasci = new JTextField ( 10 ) ;
CadastroCli . add ( datanasci );
JLabel cpf = new JLabel ();
cpf . setText ( "CPF nº: " );
CadastroCli . add ( cpf );
JTextField text_cpf = new JTextField ( 10 ) ;
CadastroCli . add ( text_cpf , BorderLayout . AFTER_LINE_ENDS );
JLabel doc_id = new JLabel ();
doc_id . setText ( "Identidade nº: " );
CadastroCli . add ( doc_id );
JTextField text_id = new JTextField ( 40 ) ;
CadastroCli . add ( text_id );
JLabel rua = new JLabel ();
rua . setText ( "Rua: " );
CadastroCli . add ( rua );
JTextField text_rua = new JTextField ( 40 ) ;
CadastroCli . add ( text_rua );
JLabel bairro = new JLabel ();
bairro . setText ( "Bairro: " );
CadastroCli . add ( bairro );
JTextField text_bairro = new JTextField ( 40 ) ;
CadastroCli . add ( text_bairro );
JLabel cidade = new JLabel ();
cidade . setText ( "Cidade: " );
CadastroCli . add ( cidade );
JTextField text_cidade = new JTextField ( 40 ) ;
CadastroCli . add ( text_cidade );
JLabel telfixo = new JLabel ();
telfixo . setText ( "Telefone Fixo: " );
CadastroCli . add ( telfixo );
JTextField text_telfixo = new JTextField ( 40 ) ;
CadastroCli . add ( text_telfixo );
JLabel telcelular = new JLabel ();
telcelular . setText ( "Telefone Celular: " );
CadastroCli . add ( telcelular );
JTextField text_telcelular = new JTextField ( 40 ) ;
CadastroCli . add ( text_telcelular );
JButton botaoincluiralterar = new JButton ();
botaoincluiralterar . setText ( "Incluir" );
CadastroCli . add ( botaoincluiralterar );
JButton botaocancelar = new JButton ();
botaocancelar . setText ( "Cancelar" );
CadastroCli . add ( botaocancelar );
JButton botaosair = new JButton ();
botaosair . setText ( "Fechar" );
CadastroCli . add ( botaosair );
cadastracliente . setContentPane ( CadastroCli );
cadastracliente . setVisible ( true );
}
public static void main ( String [] args ) {
new Janela_Cadastra_Cliente ();
}
}
ViniGodoy 13 de nov. de 2012
charleston10 13 de nov. de 2012
panel.add(label1, BorderLayout.NORTH);
panel.add(label1, BorderLayout.SOUTH);
panel.add(label1, BorderLayout.WEST);
panel.add(label2, BorderLayout.EAST);
ou use a propriedade setLocation ou setBound
;]
queroaprender 13 de nov. de 2012
Já tentei de tudo e não dá, comentei código debaixo para mudar só essa opção e não muda
JLabel nome = new JLabel ();
nome.setText ("Nome : ");
CadastroCli.add (nome);
nome.setLocation(50,60);
nome.setBounds(10, 20, 30, 40);
JTextField text_nome = new JTextField (40) ;
CadastroCli.add (text_nome);
text_nome.setLocation(150, 30);
charleston10 13 de nov. de 2012
Pode ser o tipo de layout que vc esta colocando no seu Frame…
charleston10 13 de nov. de 2012
import java.awt.* ;
class FrameWithFlowLayout {
public static void main ( String [] args ){
Frame AFrame = new Frame ( "Frame with components" );
Label lblOne = new Label ( "This is a label" );
Button btn1 = new Button ( "This is a button" );
TextField tf1 = new TextField ();
tf1 . setText ( "This is a textbox" );
AFrame . add ( lblOne );
AFrame . add ( btn1 );
AFrame . add ( tf1 );
AFrame . setSize ( 450 , 300 );
//set the layout of the frame to FlowLayout
//and align the components to the center
AFrame . setLayout ( new FlowLayout ( FlowLayout . CENTER ));
AFrame . setVisible ( true );
}
}
[img]http://www.landofcode.com/util/images/frame3.jpg[/img ]
[url]http://www.landofcode.com/java-tutorials/java-gui-layout.php[/url ]