Как перенести внешний JFrame во внутренний?
я бегиннер в Java. Моя проблема заключается в том, что я хочу чтобы мой JFrame ,который создаётся в PlayerTable, отображался в JFrame ,который создаётся в JFJB. Я пробовал присваивать один JFrame другому, но идея даже звучала сомнительно...
JFJB.java
public class JFJB extends javax.swing.JFrame {
/**
* Creates new form JFJB
*/
public JFJB() {
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() {
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem2 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton2.setText("jButton2");
jMenu1.setText("File");
jMenuItem2.setFont(new java.awt.Font("Castellar", 0, 14)); // NOI18N
jMenuItem2.setText("Make PT1");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem2);
jMenuBar1.add(jMenu1);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 659, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 279, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2.addActionListener(e -> {
PlayerTable.createPlayerTable();
});
}
/**
* @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(JFJB.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(JFJB.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(JFJB.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(JFJB.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 JFJB().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem2;
// End of variables declaration
}
PlayerTable.java
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class PlayerTable extends JFrame {
public static void createPlayerTable() {
JFrame frame = new JFrame("Test frame");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
String[] columnNames = {
"Name",
"Score"
};
String[][] data = {
{"addins", "02.11.2006 19:15", "Folder", ""},
{"AppPatch", "03.10.2006 14:10", "Folder", ""},
{"assembly", "02.11.2006 14:20", "Folder", ""},
{"Boot", "13.10.2007 10:46", "Folder", ""},
{"Branding", "13.10.2007 12:10", "Folder", ""},
{"Cursors", "23.09.2006 16:34", "Folder", ""},
{"Debug", "07.12.2006 17:45", "Folder", ""},
{"Fonts", "03.10.2006 14:08", "Folder", ""},
{"Help", "08.11.2006 18:23", "Folder", ""},
{"explorer.exe", "18.10.2006 14:13", "File", "2,93MB"},
{"helppane.exe", "22.08.2006 11:39", "File", "4,58MB"},
{"twunk.exe", "19.08.2007 10:37", "File", "1,08MB"},
{"nsreg.exe", "07.08.2007 11:14", "File", "2,10MB"},
{"avisp.exe", "17.12.2007 16:58", "File", "12,67MB"},
};
JTable table = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
frame.getContentPane().add(scrollPane);
frame.setPreferredSize(new Dimension(450, 200));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}