Originariamente inviato da Tteo
Hum... no purtroppo quella classe non va bene, perchè crea un pannello con tante diverse schede, appunto come fa windows...
Attenzione , in realtà tu crei tanti pannelli quante sono le schede , non un solo pannello.
Comunque mi sembra di capire che ti serve un layout tipico dei programmi di installazione (a step) quarda questo programmino dovrebbe andarti bene.
Non ti preccupare se i pannelli sono sovrapposti , se gestisci la visibilità java sa che , se fleggata la non visibilità , non deve neanche spendere cicli clock per disegnarla.
codice:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.*;
public class TestPanel {
static JFrame frame=new JFrame();
static JPanel p1=new JPanel();
static JPanel p2=new JPanel();
static JPanel p3=new JPanel();
static int pannelloInUso=2;
public static void main(String[] args) {
JButton b1=new JButton("avanti 1");
JButton b2=new JButton("avanti 2");
JButton b3=new JButton("avanti 3");
p1.add(b1);
p2.add(b2);
p3.add(b3);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,300);
frame.getContentPane().add(p2);
frame.getContentPane().add(p3);
frame.getContentPane().add(p1);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
managerPannelli();
frame.repaint();
frame.validate();
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
managerPannelli();
frame.repaint();
frame.validate();
}
});
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
managerPannelli();
}
});
frame.show();
}
public static void managerPannelli(){
switch(pannelloInUso){
case 1:
frame.remove(p2);
frame.remove(p3);
frame.getContentPane().add(p1);
break;
case 2:
frame.remove(p3);
frame.remove(p1);
frame.getContentPane().add(p2);
break;
case 3:
frame.remove(p2);
frame.remove(p1);
frame.getContentPane().add(p3);
break;
}
frame.repaint();
frame.validate();
pannelloInUso++;
if(pannelloInUso>3){
pannelloInUso=1;
}
}
}
Attraverso la gestione della variabile pannelloInUso gestisci i tuoi pannelli.
Ciao.