JPanel! Como adiciono um layout?

3 respostas
M

A dúvida anterior foi resolvida! Peço obrigado a todos que me ajudaram! A dúvida agora é adicionar um layout ao JPanel. No código abaixo está dando um erro: cannot resolve symbol painel = new JPanel(BoxLayout);

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

public class CadForn extends JFrame
{
   public JPanel painel;
   
   public JLabel LNome;
   public JLabel LCnpj;
   
   public JTextField TNome;
   public JTextField TCnpj;
   
   public JButton cadastra;
   public JButton cancela;
   
   
   public CadForn()
   {
      
      setTitle("Cadastro de Fornecedores");
      setSize(640, 480);
   
      addWindowListener(new WindowAdapter()
      {
         public void windowCloging(WindowEvent e)
         {
            System.exit(0);
         }
      });
      
      painel = new JPanel(BoxLayout);
            
      LNome = new JLabel("Nome");
      LCnpj = new JLabel("CNPJ/CPF");
            
      TNome = new JTextField();
      TCnpj = new JTextField();
      
      cadastra = new JButton("Cadastra");
      cancela = new JButton("Cancela");
      
      //LNome.setBounds(20, 40, 150, 30);
      //TNome.setBounds(120, 40, 150, 30);
      
      painel.add(LNome);
      painel.add(TNome);
      
      painel.add(LCnpj);
      
      painel.add(cadastra);
      painel.add(cancela);
      
      
      getContentPane().add(painel);
      
      cancela.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e)
         {
            //JOptionPane.showMessageDialog(null,"Você apertou no cadastro>Fornecedores !");
            dispose();
         }   
      });
   
       //manda mostrar o JFrame
       this.show();
   }
   
}

Minha dúvida pode ser elementar, mais não tinha onde recorrer! :oops:
Obrigado!

3 Respostas

Java_Vinicius_Machin
marvidac arrume assim:
addWindowListener(new WindowAdapter()
       {
          public void windowClosing(WindowEvent e)
          {
             System.exit(0);
          }
       });
       
       painel = new JPanel(new BorderLayout() ); //ou new FlowLayout() ou
                                            //o que for mais adequado
:wink:
S

De uma olhada em (How to Use BoxLayout: http://java.sun.com/docs/books/tutorial/uiswing/layout/box.html)

M

Continuou com o mesmo erro! :frowning:
painel = new JPanel(new BorderLayout());
^

Não sei mais o que posso fazer!
Alguém sabe?

Criado 12 de julho de 2005
Ultima resposta 12 de jul. de 2005
Respostas 3
Participantes 3