0

I am trying to replace components in jpanel using replace() in GroupLayout but it didn't worked. I tried to google it but didn't found any helpful solution. Can any one please tell me where do I making mistake?

Here is my code:

contentPanelLayout.setHorizontalGroup(
            contentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(contentPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        contentPanelLayout.setVerticalGroup(
            contentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(contentPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

I am trying to replace the panel with another panel on button click

button.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
          contentPanelLayout.replace(contentPanel,anotherPanel);
}
});

I've read the java docs, but not found any helpful.

Vighanesh Gursale
  • 921
  • 5
  • 15
  • 31
  • 2
    It might help you [How to Use GroupLayout](http://docs.oracle.com/javase/tutorial/uiswing/layout/group.html) – Braj May 31 '14 at 15:37
  • Call `revalidate()` and `repaint()`, search "How to replace/add/remove a swing comonent" – DSquare May 31 '14 at 15:45
  • 2
    I am trying to replace the panel with another panel on button click == CardLayout, – mKorbel May 31 '14 at 19:09

0 Answers0