Я хочу добавить JFrame из другого класса с именем: Home к другому Jframe в классе Dashboard, когда я нажимаю на кнопку Home, должно быть содержимое класса Home в mainPnale, но когда я его запускаю, он показывает эту ошибку : Исключение в потоке "AWT-EventQueue-0" java .lang.IllegalArgumentException: добавление окна в контейнер, поэтому, пожалуйста, помогите мне, спасибо alote
это панель инструментов Интерфейс, когда я нажимаю кнопку Home, должен импортировать Panel из класса Home, как второй пи c, это интерфейс класса Home
это функция при нажатии кнопки home из класса Dashboard:
private void panelHomeMouseClicked(java.awt.event.MouseEvent evt) {
panelcontent.removeAll();
Home he = new Home();
panelcontent.add(he);
}
и это класс Home:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package project;
/**
*
* @author MR-INT
*/
public class Home extends javax.swing.JFrame {
/**
* Creates new form Home
*/
public Home() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
panelMainContent3 = new javax.swing.JPanel();
lblcontent3 = new javax.swing.JLabel();
jRadioButtonMenuItem1 = new javax.swing.JRadioButtonMenuItem();
home_form1 = new javax.swing.JPanel();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
panelMainContent3.setPreferredSize(new java.awt.Dimension(300, 350));
lblcontent3.setText("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
javax.swing.GroupLayout panelMainContent3Layout = new javax.swing.GroupLayout(panelMainContent3);
panelMainContent3.setLayout(panelMainContent3Layout);
panelMainContent3Layout.setHorizontalGroup(
panelMainContent3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelMainContent3Layout.createSequentialGroup()
.addGap(375, 375, 375)
.addComponent(lblcontent3)
.addContainerGap(436, Short.MAX_VALUE))
);
panelMainContent3Layout.setVerticalGroup(
panelMainContent3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelMainContent3Layout.createSequentialGroup()
.addGap(153, 153, 153)
.addComponent(lblcontent3)
.addContainerGap(181, Short.MAX_VALUE))
);
jRadioButtonMenuItem1.setSelected(true);
jRadioButtonMenuItem1.setText("jRadioButtonMenuItem1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton2.setText("jButton2");
jLabel1.setText("Welcome to the main home");
jButton1.setText("jButton1");
jButton3.setText("jButton3");
javax.swing.GroupLayout home_form1Layout = new javax.swing.GroupLayout(home_form1);
home_form1.setLayout(home_form1Layout);
home_form1Layout.setHorizontalGroup(
home_form1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(home_form1Layout.createSequentialGroup()
.addContainerGap(279, Short.MAX_VALUE)
.addGroup(home_form1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, home_form1Layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(54, 54, 54)
.addComponent(jButton2)
.addGap(318, 318, 318))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, home_form1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(336, 336, 336))))
.addGroup(home_form1Layout.createSequentialGroup()
.addGap(347, 347, 347)
.addComponent(jButton3)
.addGap(0, 0, Short.MAX_VALUE))
);
home_form1Layout.setVerticalGroup(
home_form1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, home_form1Layout.createSequentialGroup()
.addGap(52, 52, 52)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 167, Short.MAX_VALUE)
.addComponent(jButton3)
.addGap(79, 79, 79)
.addGroup(home_form1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton1))
.addGap(157, 157, 157))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(home_form1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(home_form1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Home().setVisible(true);
}
});
}
// Variables declaration - do not modify
public javax.swing.JPanel home_form1;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem1;
private javax.swing.JLabel lblcontent;
private javax.swing.JLabel lblcontent1;
private javax.swing.JLabel lblcontent2;
public javax.swing.JLabel lblcontent3;
private javax.swing.JPanel panelMainContent;
private javax.swing.JPanel panelMainContent1;
private javax.swing.JPanel panelMainContent2;
private javax.swing.JPanel panelMainContent3;
// End of variables declaration
}