I get an idea where i design panel contents graphically and all it's possible methods in a jframe then i use that panel in another jframe where all i need to do is to create instance of the other frame and get it panel and affect it to a panel in my current jframe.
here is the code that i tried the first jframe that contains my designed panel model :
package chemsou;
import java.util.Hashtable;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
public class CheckListe extends javax.swing.JFrame {
/**
* Creates new form NewJFrame
*/
Hashtable<String, JCheckBox> model = new Hashtable<>();
public JPanel getPanel(){
return jPanel1;
}
public CheckListe(String[] list) {
initComponents();
jPanel1.setLayout(new java.awt.GridLayout(0, 1, 0, 4));
for (String element : list) {
model.put(element, new JCheckBox(element));
jPanel1.add(model.get(element));
}
}
public CheckListe() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new java.awt.GridLayout(0, 1, 0, 4));
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(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 388, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 535, 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(CheckListe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(CheckListe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(CheckListe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(CheckListe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CheckListe().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
my jframe where i call the first frame and i set the panel to the modeled one :
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String[] list =new String[]{"e1","e2","e3"};
CheckListe checkListe = new CheckListe(list);
// CheckListePanel.setLayout(checkListe.getPanel().getLayout());
CheckListePanel = checkListe.getPanel();
checkListe.setVisible( true );
CheckListePanel.setVisible(true);
CheckListePanel.setSize(100, 500);
CheckListePanel.revalidate();
CheckListePanel.repaint();
System.out.println("done");
}
When I run the code I can see that the other jframe contains the designed panel but the caller jframe dont do anything
what I m supposed to do ?