问题是我在窗格之间切换,我的按钮和文本字段变得不可见,但是然后我将光标拖到组件上,它们就出现了。 我的层次结构与此类似:
的JFrame
__ 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);
}
}
答案 0 :(得分:0)
切换窗格时,应调用revalidate()
和repaint()
方法。
frame.getContentPane().revalidate();
frame.getContentPane().repaint();
来自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.
从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.
按照camickr的评论编辑。