[英]replacing one jpanel with another jpanel
我想替換當前面板並在JPanel
表單中調用另一個面板。 我嘗試使用setContentPane()
和getContentPane()
方法來執行操作,但它給出了錯誤。 我該怎么做...。我也嘗試了一下,但清除了所有組件,但不添加任何內容
private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
if (new ConnectionFactory().userLoginCheck(usernameText.getText(), new String(passwordText.getPassword()))) {
removeAll();
add(new ChangeUsernamePassword());
revalidate();
repaint();
//new Welcomeboard();
} else {
warningLabel.setText("Invalid Username Or Password!!!");
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(DashboardPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(DashboardPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
“我想替換當前面板並以JPanel形式調用另一個面板”
與其嘗試添加移除面板, CardLayout
使用CardLayout
。 要查看您如何使用Netbeans GUI Builder,請參閱如何將CardLayout與Netbeans GUI Builder一起使用 。 CardLayout
作用是允許您在不同的視圖之間進行更改,而無需添加和放置面板,這可能很麻煩。
另外,您可能想調試if語句。 僅顯示少量代碼就很難說清楚。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.