我有一个包含很多面板的项目。我有一种方法可以在卡布局面板中切换卡(jpanel)(见下文)。当我从IDE(Netbeans)运行它并从命令提示符(java -jar MyStuff.jar
)运行jar时,这一切都正常。但是,当我双击Jar时,卡片会发生变化,但repaint
不会产生不良结果(当鼠标悬停在组件上时)。如果我再次点击按钮再次调用该方法,它将适用。我需要立即帮助:)谢谢!
/**
* Shows a panel by the given panel name (in the cardPanel)
*
* @param panelName
*/
private void showPanel(String panelName) {
if (panelName.equals("revenueSources")) {
backButtonIcon.setVisible(false);
} else {
backButtonIcon.setVisible(true);
}
currentPanelName = panelName;
((CardLayout) cardPanel.getLayout()).show(cardPanel, panelName);
repaint();
revalidate();
}
答案 0 :(得分:3)
(when I mouse over the components appear)
此代码仅从
repaint();
revalidate();
到
revalidate();
repaint();