[nbusers] Java; JPanel within JFrame will not show components.

  • From: "coderkid" < >
  • To:
  • Subject: [nbusers] Java; JPanel within JFrame will not show components.
  • Date: Thu, 11 Oct 2012 23:16:24 -0400

Hey guys, this is my first post. I've been having problems with programming 
Java in Netbeans and have not been able to find an answer.
First of all, I'll tell you about my application. I have made a single frame 
application with the main view acting as a menu. Clicking on one of the 
buttons on this menu opens up a new JFrame. I want to have two text fields 
and two buttons within this JFrame and have split these components into their 
own JPanels (2 buttons in one panel, two text fields in the other) to do so. 
The problem is, the components I have do not show up on the JFrame. Here is 
my code: 

 public void whichIsLargerButtonActionPerformed(java.awt.event.ActionEvent 
evt){
       javax.swing.JFrame wILFrame = new JFrame("Which Is Larger?");  // 
Panel is a Container
       javax.swing.JPanel wILPanel1 = new JPanel ();
       javax.swing.JPanel wILPanel2 = new JPanel ();
       wILPanel1.setLayout(new BorderLayout());
       JButton wILCalculateButton = new JButton("Calculate");  // Button is a 
Component
       JTextField wILtextField1 = new JTextField ("wILtextField1");
       JTextField wILtextField2 = new JTextField ("wILtextField2");
       JButton wILExitButton = new JButton ("wILExitButton");
        wILFrame.setVisible(true);
        wILPanel1.setVisible(true);
        wILPanel2.setVisible(true);
        wILPanel2.add(wILCalculateButton);             // The Panel Container 
adds a Button Component
        wILPanel1.add(wILtextField1);
        wILPanel1.add(wILtextField2);
        wILPanel2.add(wILExitButton);
        
        wILFrame.setSize(400,400);
        wILFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
initComponents ();
 wILExitButton.setText("Exit");
         //sets the text shown on exitButton, as depicted in exitButton.text
        wILExitButton.setName("wILExitButton"); // NOI18N
        //sets name for exitButton
        wILExitButton.addActionListener(new java.awt.event.ActionListener() {
            //adds action listener to exitButton
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                wILExitButtonActionPerformed(evt);
                //sets what happens when exitButton is pressed
            }
             });


Does anybody know why none of my components show up in the JFrame? Help would 
be much appreciated (the sooner, the better as this project is due Sunday). 
The full code of the mainMathMethodsView.java will be in the text file linked 
here.




Attachments: 
http://forums.netbeans.org//files/mathmethodsview_full_code_851.txt



[nbusers] Java; JPanel within JFrame will not show components.

coderkid 10/12/2012

[nbusers] Java; JPanel within JFrame will not show components.

kimp_07 10/12/2012

[nbusers] Re: Java; JPanel within JFrame will not show components.

Chuck Davis 10/12/2012

[nbusers] Java; JPanel within JFrame will not show components.

coderkid 10/13/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close