Estou fazendo uma interface q coloquei dentro de um JFrame um JPanel, dentro deste JPanel inicial coloquei alguns botoes que ao o usuario clicar em algum destes botoes, quero que abra um JPanel em cima deste antigo…
O que coloquei foi:
jPanel1.setVisible(false);
jPanel2.setVisible(true);
Porem no meu jPanel2, tenho um JTextField, e quando coloco pra executar o programa inicialmente alem de aparecer os botoes do jPanel1, aparece o JTextField do jPanel 2, e eu gostaria q aparece apenas o q esta contido em jPanel1… o que eu poderia fazer para arrumar isto?
Ai meu beleza!!
cara você terá que setar os componentes do JPanel2 para false e criar uma rotina tipo
quando clicar em algum botão set os componentes JPanel1 para false e JPanel2 para true.
import java.awt.;
import javax.swing.;
public class JPanelExe extends JFrame{
JPanel p,pp;
JButton a,b;
JTextField t,tt;
public JPanelExe() {
Container tela = getContentPane();
p = new JPanel();
a = new JButton("nao");
a.setVisible(true);
p.add(a);
pp = new JPanel();
b = new JButton("ok");
b.setVisible(false);
p.add(b);
add(p);
setVisible(true);
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//mais ou menos assim
class Evento implements ActionListener{
public void actionPerformed(ActionEvent e){
if (e.getSource()== a){
a.setVisible(false);
b.setVisible(true);
}
if (e.getSource()== b){
a.setVisible(true);
b.setVisible(false);
}
}
}
public static void main(String[] args) {
JPanelExe app = new JPanelExe();
}