Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>IMO, you have to add your own JPanel into ContentPane of JFrame.</p> <p>Besides, use SwingUtilities to show GUI.</p> <pre><code> public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame f = new JFrame(); NewJPanel n1 = new NewJPanel(); f.getContentPane().add(n1, BorderLayout.CENTER); f.pack(); f.show(); } }); } </code></pre> <p>Class NewJPanel code.</p> <pre><code>class NewJPanel extends javax.swing.JPanel { /** Creates new form NewJPanel */ public NewJPanel() { //pag kinoment ko ito, tsaka lang lamalabas yung jlabel. 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") // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt; private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel1.setText("jLabel1"); JLabel n = new JLabel(); n.setText("asdasdasd"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(175, 175, 175) .addComponent(jLabel1) .addComponent(n) .addContainerGap(191, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(127, 127, 127) .addComponent(jLabel1) .addComponent(n) .addContainerGap(159, Short.MAX_VALUE)) ); }// &lt;/editor-fold&gt; // Variables declaration - do not modify private javax.swing.JLabel jLabel1; // End of variables declaration } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload