Erro em mostrar todos os componentes

1 resposta
0
import javax.swing.JFrame; 
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.JLabel; 
import javax.swing.ImageIcon;

 
public class MeuNote extends JFrame{  
   private JTextArea texto = new JTextArea(); 
	private JButton zero = new JButton("ok");
	private JLabel lab = new JLabel("Você vai?");
	 
      public MeuNote(){  
      super("Meu Notepad");  
      this.montaJanela();  
    }   
   
    private void montaJanela(){  

		this.getContentPane().add(lab);
		this.getContentPane().add(zero);
		this.getContentPane().add(texto);

	}  
       
    public static void main(String[] args){  
        //Cria objeto: 
        MeuNote janela = new MeuNote();
		janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);		
		janela.setVisible(true);
		janela.setSize(640,480);
				
    }  
 }

legal isso mas tipo se eu ponho SteLayout(Null); só mostra o Jbutton se eu n~/ao ponho mostra o Jbutton ocupando a tela inteira (pois não tem como da um SetSize e SetLocation :()

o que eu faço pra aparecer tudo?

1 Resposta

R

Se você não quiser usar um gerenciador de layout, use JFrame.setLayout(null) e ajuste o tamanho/posição de cada elemento que você inserir no JFrame com setBounds(). O código que você mostrou não ajusta o gerenciador de layout de forma específica, e portanto será usado o padrão do Swing, que é BorderLayout. Considero que uma boa solução para o seu problema seria usar FlowLayout, recomendo ver os links abaixo:

http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html
http://java.sun.com/docs/books/tutorial/uiswing/layout/flow.html

Criado 19 de maio de 2009
Ultima resposta 19 de mai. de 2009
Respostas 1
Participantes 2