jeudi 23 juin 2016
JFrame displays itself and the frame before it
I am calling a JFrame (JFrame1) via an ActionPreformed in another class. When I click the JButton, JFrame1 pops up, but it has the contents for itself and the frame before it (where the button was). Is the JFrame not opaque? Do I need a JPanel?
Calling JFrame1:
public void HelpActionPerformed(java.awt.event.ActionEvent evt) {
NewJFrame1 open = new NewJFrame1();
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
open.setVisible(true);
}
});
}
JFrame 1:
import javax.swing.JPanel;
public class NewJFrame1 extends OriginalJFrame {
public NewJFrame1() {
initComponents();
}
@SuppressWarnings("unchecked")
NewJFrame1 open;
public void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel5 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();
jLabel6 = new javax.swing.JLabel();
jScrollPane4 = new javax.swing.JScrollPane();
jTextArea3 = new javax.swing.JTextArea();
jLabel7 = new javax.swing.JLabel();
jScrollPane5 = new javax.swing.JScrollPane();
jTextArea4 = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/original/jframe/logo4.png")));
jLabel1.setText("jLabel1");
jLabel2.setFont(new java.awt.Font("Calibri", 0, 14));
jLabel2.setText("Help");
jLabel3.setFont(new java.awt.Font("Calibri", 0, 14));
jLabel3.setText("Frequently Asked Questions:");
jLabel4.setFont(new java.awt.Font("Calibri", 0, 14));
jLabel4.setText("Text");
jTextArea1.setColumns(20);
jTextArea1.setFont(new java.awt.Font("Calibri", 0, 14));
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jTextArea1.setText("text");
jScrollPane1.setViewportView(jTextArea1);
jLabel5.setFont(new java.awt.Font("Calibri", 0, 14));
jLabel5.setText("text");
jTextArea2.setColumns(20);
jTextArea2.setFont(new java.awt.Font("Calibri", 0, 14));
jTextArea2.setLineWrap(true);
jTextArea2.setRows(5);
jTextArea2.setText("text");
jScrollPane2.setViewportView(jTextArea2);
jLabel6.setFont(new java.awt.Font("Calibri", 0, 14));
jLabel6.setText("text");
jTextArea3.setColumns(20);
jTextArea3.setFont(new java.awt.Font("Calibri", 0, 14));
jTextArea3.setLineWrap(true);
jTextArea3.setRows(5);
jTextArea3.setText("text");
jScrollPane4.setViewportView(jTextArea3);
jLabel7.setFont(new java.awt.Font("Calibri", 0, 14));
jLabel7.setText("text");
jTextArea4.setColumns(20);
jTextArea4.setFont(new java.awt.Font("Calibri", 0, 14));
jTextArea4.setLineWrap(true);
jTextArea4.setRows(5);
jTextArea4.setText("text");
jScrollPane5.setViewportView(jTextArea4);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(16, 16, 16)
.addComponent(jLabel3))
.addGroup(layout.createSequentialGroup()
.addGap(48, 48, 48)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(jLabel4)
.addComponent(jLabel7)
.addComponent(jLabel6)))
.addGroup(layout.createSequentialGroup()
.addGap(80, 80, 80)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 710, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 710, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 710, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 710, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 12, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(16, 16, 16)
.addComponent(jLabel2)))
.addGap(0, 0, Short.MAX_VALUE)))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
/**
*
* @param args
*/
public static void second(String args[]) {
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 | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
}
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea jTextArea2;
private javax.swing.JTextArea jTextArea3;
private javax.swing.JTextArea jTextArea4;
}
Update:
public void HelpActionPerformed(java.awt.event.ActionEvent evt) {
java.awt.EventQueue.invokeLater(() -> {
JFrame frame1 = new JFrame ();
JPanel panel1 = new JPanel ();
frame1.getContentPane().add(panel1);
jLabel10 = new javax.swing.JLabel();
jLabel20 = new javax.swing.JLabel();
jSeparator10 = new javax.swing.JSeparator();
jLabel30 = new javax.swing.JLabel();
jLabel40 = new javax.swing.JLabel();
jScrollPane10 = new javax.swing.JScrollPane();
jTextArea10 = new javax.swing.JTextArea();
jLabel50 = new javax.swing.JLabel();
jScrollPane20 = new javax.swing.JScrollPane();
jTextArea20 = new javax.swing.JTextArea();
jLabel60 = new javax.swing.JLabel();
jScrollPane40 = new javax.swing.JScrollPane();
jTextArea30 = new javax.swing.JTextArea();
jLabel70 = new javax.swing.JLabel();
jScrollPane50 = new javax.swing.JScrollPane();
jTextArea40 = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource(" "))); // NOI18N
jLabel10.setText("jLabel1");
jLabel20.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
jLabel20.setText("Help");
jLabel30.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
jLabel30.setText("Frequently Asked Questions:");
jLabel40.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
jLabel40.setText(" ");
jTextArea10.setColumns(20);
jTextArea10.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
jTextArea10.setLineWrap(true);
jTextArea10.setRows(5);
jTextArea10.setText(" ");
jScrollPane10.setViewportView(jTextArea1);
jLabel50.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
jLabel50.setText(" ");
jTextArea20.setColumns(20);
jTextArea20.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
jTextArea20.setLineWrap(true);
jTextArea20.setRows(5);
jTextArea20.setText(" ");
jScrollPane20.setViewportView(jTextArea20);
jLabel60.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
jLabel60.setText(" ");
jTextArea30.setColumns(20);
jTextArea30.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
jTextArea30.setLineWrap(true);
jTextArea30.setRows(5);
jTextArea30.setText(" ");
jScrollPane40.setViewportView(jTextArea30);
jLabel70.setFont(new java.awt.Font("Calibri", 0, 14));
jLabel70.setText("");
jTextArea40.setColumns(20);
jTextArea40.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
jTextArea40.setLineWrap(true);
jTextArea40.setRows(5);
jTextArea40.setText(" ");
jScrollPane50.setViewportView(jTextArea40);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(16, 16, 16)
.addComponent(jLabel30))
.addGroup(layout.createSequentialGroup()
.addGap(48, 48, 48)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel50)
.addComponent(jLabel40)
.addComponent(jLabel70)
.addComponent(jLabel60)))
.addGroup(layout.createSequentialGroup()
.addGap(80, 80, 80)
.addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 710, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jScrollPane50, javax.swing.GroupLayout.PREFERRED_SIZE, 710, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane20, javax.swing.GroupLayout.PREFERRED_SIZE, 710, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane40, javax.swing.GroupLayout.PREFERRED_SIZE, 710, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 12, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator10)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(16, 16, 16)
.addComponent(jLabel20)))
.addGap(0, 0, Short.MAX_VALUE)))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel10)
.addGap(18, 18, 18)
.addComponent(jLabel20)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator10, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel30)
.addGap(18, 18, 18)
.addComponent(jLabel40)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel50)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane20, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel70)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane40, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel60)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane50, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
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 | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
frame1.setVisible(true);
});
};
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel20;
private javax.swing.JLabel jLabel30;
private javax.swing.JLabel jLabel40;
private javax.swing.JLabel jLabel50;
private javax.swing.JLabel jLabel60;
private javax.swing.JLabel jLabel70;
private javax.swing.JScrollPane jScrollPane10;
private javax.swing.JScrollPane jScrollPane20;
private javax.swing.JScrollPane jScrollPane40;
private javax.swing.JScrollPane jScrollPane50;
private javax.swing.JSeparator jSeparator10;
private javax.swing.JTextArea jTextArea10;
private javax.swing.JTextArea jTextArea20;
private javax.swing.JTextArea jTextArea30;
private javax.swing.JTextArea jTextArea40;
Now it repaints the frame (with both frames' content) instead of popping up and there is a dark area in the upper right.
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire