hi all!i have problem to show JPanel in netbean with button here's the code

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        NewJPanel x = new NewJPanel();
        x.setVisible(true);
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 30, Short.MAX_VALUE)
            .addComponent(x)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 30, Short.MAX_VALUE)
            .addComponent(x)
        );

my question how to show another panel cause but the first show is hidden or destroy cause i have try for show JPanel2 with same container its impinge by JPanel1,like this

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        NewJPanel z = new NewJPanel2();
        z.setVisible(true);
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 30, Short.MAX_VALUE)
            .addComponent(z)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 30, Short.MAX_VALUE)
            .addComponent(z)
        );

or any better idea for showing JPanel!cause i have 15 button and 15 JPanel for showing in 1 frame!thanks all

Recommended Answers

All 2 Replies

Hi
It looks like you have copy pasted your code and forgot to change some of it?
One example is that the vertical alignment should be BASELINE not LEADING.

I do not use Netbeans and have never made this kind of GroupLayout so I will not comment more about your code afraid to give you wrong advise.
I think maybe this tutorial can give you some help: http://weblogs.java.net/blog/tpavek/archive/2006/02/getting_to_know_1.html

One other layout form to use could be a GridbagLayout.
If every panel and button should have exactly the same space in a matrix you can also use an ordinary GridLayout.
Good luck =)

its true i have to paste from generated code!cause its a simply for showing JPanel!that code is container for JPanel i want showing,i mean like this,container(JPanel1),want showing(JPanel2),in a application JPanel2 have parent JPanel1,thanks for referension

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.