Jpanel disappearing while getting a get on it

Asked

Viewed 46 times

0

I am building a layered application using the Spring Framework, I am new and well be doing it the wrong way.

My problem is this, as you can see in the image below I have the PrincipalFrame and the PessoaFrame > PessoaPanel, I need to use the PessoaPanel in several places of the system because it is a way for the user to search for anyone in the system, at the moment I need to use it in the PrincipalFrame and in the PessoaFrame but the shares (Listeners) are in PessoaListaController and I don’t think it’s good practice to declare everything again on PrincipalController because it will be two places to give function maintenance for the same goal. The problem is that when I do:

PrincipalFrame.getTabMenuGeral().add("Pessoas", pessoaListaController.getPessoaPanel());

and then I will call again the Panel elsewhere in the system, it ends up becoming invisible, I have tried the following below:

frame.repaint();
frame.getPessoaPanel().visible(true);

Illustration: inserir a descrição da imagem aqui

What is my Personal Panel: inserir a descrição da imagem aqui

1 answer

2


After much searching, I ended up arriving at the answer unintentionally.

I did this, I created a class PessoaPanelController and established the PessoaPanel in it, I called the @PostConstruct and initialized all buttons on PessoaPanel and now when I need PessoaPanel me of the one @Autowired in my component and use, but the real answer was @Scope("prototype") which makes it so that every time I urge Personpanelcontroller the system creates a new separate instance and no one competes with anyone, follows below mine Controller;

@Component
@Scope("prototype")
public class PessoaPanelController extends AbstractController {

@Autowired
public PessoaPanel frame;

@Autowired
private PessoaController pessoaController;

@Autowired
private PessoaService pessoaService;

public PessoaPanelController() { }

@PostConstruct
public void init() {        
/********************************************************************************/
/** Pessoa ToolBar **************************************************************/
/********************************************************************************/
    registerAction(this.frame.getBtnPessoaNovo(), new AbstractAction() {
        protected void action() { frame.showPopupMenuPessoa(); }
    });

    registerAction(this.frame.getPopupMenu().getMnuPessoaNovoFisica(), new AbstractAction() {
        protected void action() { pessoaController.show(); }
    });

    registerAction(this.frame.getBtnPessoaEditar(), new AbstractAction() {
        protected void action() { pessoaEditar(); }
    });

    registerAction(this.frame.getBtnPessoaExcluir(), new AbstractAction() {
        protected void action() { pessoaExcluir(); }
    });

    registerAction(this.frame.getBtnPessoaPesquisar(), new AbstractAction() {
        protected void action() { refreshTablePessoa(); }
    });

    this.frame.getTablePessoa().addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent event) {                
            if(event.getClickCount() == 2) {
                pessoaEditar();
            }
        }
    });

    this.frame.getTablePessoa().addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            frame.getBtnPessoaEditar().setEnabled(true);
            frame.getBtnPessoaExcluir().setEnabled(true);
        }
    });
}

public void refreshTablePessoa() {  
    this.frame.refreshTablePessoa(this.pessoaService.getAllPessoas());
}

public void pessoaEditar() {
    Pessoa p = frame.getTablePessoa().getPessoaSelected();
    if(p != null) {
        this.pessoaController.show(p);
    }
}

public void pessoaExcluir() {
    Pessoa p = frame.getTablePessoa().getPessoaSelected();

    if(p != null) {
        int opcao = JOptionPane.showConfirmDialog(null, 
                "Confirma a exclusão deste(s) registro(s)?",
                "Atenção",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.INFORMATION_MESSAGE);

        if(opcao == 0) {
            this.pessoaService.delete(p.getPessoaId());
        }
    }
}

public PessoaPanel getPanel() {
    return frame;
}   

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.