Salve galera…Estou tentando add um JPanel a uma área de um JFrame mas não estou conseguindo, esse JPanel eh para ser adicionado com um evento de click num JMenuItem.
to tentando assim
//classe extend JPanel
public class DesktopArea extends JPanel{
private static int deskCount;
public DesktopArea(){
JLabel label = new JLabel("" + deskCount);
label.setForeground(Color.WHITE);
this.add(label);
this.setBackground(Color.BLACK);
this.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
deskCount++;
}
public Integer getDeskCount(){
return this.deskCount;
}
}
// JFrame, metodo de inicializacao no JFrame
public class FramePrincipal extends JFrame{
public FramePrincipal(){
begin();
}
}
public void begin(){
DesktopArea deskArea = new DesktopArea();
this.setExtendedState(MAXIMIZED_BOTH);
this.setLayout(new BorderLayout());
this.add(panelNorth, BorderLayout.NORTH);
this.getContentPane().add(deskArea, BorderLayout.CENTER); //aqui funciona a primeira vez, qdo coloco esse metodo no construtor do JFrame
this.add(panelSouth, BorderLayout.SOUTH);
this.setTitle("Project" + deskArea.getDeskCount());
}
//aqui onde eu tento adicionar novamente o JPanel ao JFrame FramePrincipal
private void fileNewActionPerformed(java.awt.event.ActionEvent evt) {
DesktopArea deskArea = new DesktopArea();
this.getContentPane().add(deskArea, BorderLayout.CENTER); //aqui onde tento add o JPanel
this.setTitle("Project" + deskArea.getDeskCount());
this.getContentPane().repaint();
}
Como resolver isso ???
obrigado