Domanda

The problem is then I switch between panes, my buttons and text-fields become not visible, but then I drag cursor over components, they appear. My Hierarchy looks similar to this:

JFrame

  • PanelWithComponents
  • _Button3
  • PanelWithPanels
  • _PanelOne
  • __Button1
  • __Label1(Background)
  • _PanelTwo
  • __Label2(Background)
  • __Button2

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                              
     if (jRadioButton1.isSelected()){
        CardLayout cl = (CardLayout)(bottomPanel.getLayout());
        cl.next(bottomPanel);
    
    }else{
        CardLayout cl = (CardLayout)(bottomPanel.getLayout());
        cl.next(bottomPanel);
    
    
     }
    

    }

È stato utile?

Soluzione

You should call the revalidate() and repaint() method when you switch the panes.

frame.getContentPane().revalidate();
frame.getContentPane().repaint();

From add method of Container.

Note: If a component has been added to a container that has been displayed, validate must be called on that container to display the new component. If multiple components are being added, you can improve efficiency by calling validate only once, after all the components have been added.

From remove method of Container.

Note: If a component has been removed from a container that had been displayed, validate() must be called on that container to reflect changes. If multiple components are being removed, you can improve efficiency by calling validate() only once, after all the components have been removed.

Edited as per camickr's comment.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top