Note that there are some explanatory texts on larger screens.

plurals
  1. POJPanel is not shown after adding it to JFrame
    primarykey
    data
    text
    <p>I have to setup a basic JAVA application including a GUI based on swing. My idea was to create one JFrame and different JPanels and based on the users input to change the shown JPanel. After running my application the JFrame is shown but not the content of the JPanel. I thought up to here it should be strait forward... but as it seems it isn't. Hope you can give me a hint :)</p> <p>Here is my main:</p> <pre><code>public class Client { public static void main(String[] args) { MainWindow window = new MainWindow(); window.setVisible(true); LoginView pane = new LoginView(); window.getContentPane().add(pane); window.invalidate(); window.repaint(); } } </code></pre> <p>my MainWindow:</p> <pre><code>package client; public class MainWindow extends javax.swing.JFrame { public MainWindow() { 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") private void initComponents() { setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(0, 352, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(0, 250, Short.MAX_VALUE) ); pack(); } } </code></pre> <p>my LoginView:</p> <pre><code>package client.views; public class LoginView extends javax.swing.JPanel { public LoginView() { 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") private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel1.setText("Login"); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(jLabel1) .addContainerGap(345, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(jLabel1) .addContainerGap(264, Short.MAX_VALUE)) ); } private javax.swing.JLabel jLabel1; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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