Need help making Objects visable (swing)

Discussion in 'Java' started by NNTPmail@flashmail.com, Dec 15, 2006.

  1. Guest

    In the following code, Main().jButton1's ActionPerformed does not
    result in a visable SubForm. What am I doing wrong?

    /*
    * Main.java
    *
    * Created on December 14, 2006, 6:02 PM
    */

    package Test;

    /**
    *
    * @author Administrator
    */
    public class Main extends javax.swing.JFrame {

    /** Creates new form Main */
    public Main() {
    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.
    */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">

    private void initComponents() {
    jButton1 = new javax.swing.JButton();


    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jButton1.setText("jButton1");
    jButton1.addActionListener(new java.awt.event.ActionListener()
    {
    public void actionPerformed(java.awt.event.ActionEvent evt)
    {
    jButton1ActionPerformed(evt);
    }
    });

    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, 400, Short.MAX_VALUE)
    .add(jButton1)
    );
    layout.setVerticalGroup(

    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(0, 300, Short.MAX_VALUE)
    .add(jButton1)
    );
    pack();
    }// </editor-fold>

    private void jButton1ActionPerformed(java.awt.event.ActionEvent
    evt) {
    new SubForm().setVisible(true);
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new Main().setVisible(true);
    }
    });
    }

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    // End of variables declaration

    }


    /*
    * SubForm.java
    *
    * Created on December 14, 2006, 6:02 PM
    */

    package Test;

    /**
    *
    * @author Administrator
    */
    public class SubForm extends javax.swing.JPanel {

    /** Creates new form SubForm */
    public SubForm() {
    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.
    */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">

    private void initComponents() {
    jLabel1 = new javax.swing.JLabel();

    jLabel1.setText("SubForm Showing");

    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()
    .add(182, 182, 182)
    .add(jLabel1)
    .addContainerGap(133, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(

    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(layout.createSequentialGroup()
    .add(84, 84, 84)
    .add(jLabel1)
    .addContainerGap(202, Short.MAX_VALUE))
    );
    }// </editor-fold>


    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    // End of variables declaration

    }
    , Dec 15, 2006
    #1
    1. Advertising

  2. wrote:
    > In the following code, Main().jButton1's ActionPerformed does not
    > result in a visable SubForm. What am I doing wrong?
    >
    > /*
    > * Main.java
    > *
    > * Created on December 14, 2006, 6:02 PM
    > */
    >
    > package Test;
    >
    > /**
    > *
    > * @author Administrator
    > */
    > public class Main extends javax.swing.JFrame {
    >
    > /** Creates new form Main */
    > public Main() {
    > 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.
    > */
    > // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    >
    > private void initComponents() {
    > jButton1 = new javax.swing.JButton();
    >
    >
    > setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    > jButton1.setText("jButton1");
    > jButton1.addActionListener(new java.awt.event.ActionListener()
    > {
    > public void actionPerformed(java.awt.event.ActionEvent evt)
    > {
    > jButton1ActionPerformed(evt);
    > }
    > });
    >
    > 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, 400, Short.MAX_VALUE)
    > .add(jButton1)
    > );
    > layout.setVerticalGroup(
    >
    > layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    > .add(0, 300, Short.MAX_VALUE)
    > .add(jButton1)
    > );
    > pack();
    > }// </editor-fold>
    >
    > private void jButton1ActionPerformed(java.awt.event.ActionEvent
    > evt) {
    > new SubForm().setVisible(true);
    > }
    >
    > /**
    > * @param args the command line arguments
    > */
    > public static void main(String args[]) {
    > java.awt.EventQueue.invokeLater(new Runnable() {
    > public void run() {
    > new Main().setVisible(true);
    > }
    > });
    > }
    >
    > // Variables declaration - do not modify
    > private javax.swing.JButton jButton1;
    > // End of variables declaration
    >
    > }
    >
    >
    > /*
    > * SubForm.java
    > *
    > * Created on December 14, 2006, 6:02 PM
    > */
    >
    > package Test;
    >
    > /**
    > *
    > * @author Administrator
    > */
    > public class SubForm extends javax.swing.JPanel {
    >
    > /** Creates new form SubForm */
    > public SubForm() {
    > 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.
    > */
    > // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    >
    > private void initComponents() {
    > jLabel1 = new javax.swing.JLabel();
    >
    > jLabel1.setText("SubForm Showing");
    >
    > 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()
    > .add(182, 182, 182)
    > .add(jLabel1)
    > .addContainerGap(133, Short.MAX_VALUE))
    > );
    > layout.setVerticalGroup(
    >
    > layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    > .add(layout.createSequentialGroup()
    > .add(84, 84, 84)
    > .add(jLabel1)
    > .addContainerGap(202, Short.MAX_VALUE))
    > );
    > }// </editor-fold>
    >
    >
    > // Variables declaration - do not modify
    > private javax.swing.JLabel jLabel1;
    > // End of variables declaration
    >
    > }
    >


    Your code is a mess. You will get much better help if you post a simple
    compilable example.

    As to your problem, SubForm is not a top level window and setting
    visible on it will do nothing. If you to see it, add it to a JFrame or
    JWindow and show the window.

    knute...
    Knute Johnson, Dec 15, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Big Daddy

    Java 1.2 Swing vs. Java 1.5 Swing

    Big Daddy, Apr 15, 2005, in forum: Java
    Replies:
    2
    Views:
    499
    Pete Barrett
    Apr 16, 2005
  2. Bill Burke

    visable/invisable button

    Bill Burke, Oct 1, 2005, in forum: HTML
    Replies:
    5
    Views:
    499
    Dima Gofman
    Oct 2, 2005
  3. Replies:
    2
    Views:
    358
    Diego Martins
    May 19, 2006
  4. Yankee Imperialist Dog

    setting an html control to visable="true/false"

    Yankee Imperialist Dog, Jul 23, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    324
    clintonG
    Jul 24, 2008
  5. Kivak Wolf
    Replies:
    0
    Views:
    317
    Kivak Wolf
    Jun 19, 2009
Loading...

Share This Page