Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Whats wrong with this it's not displaying inside component

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Whats wrong with this it's not displaying inside component

    package san_ims;
    import javax.swing.*;
    import java.sql.*;
    public class help extends javax.swing.JFrame{
     
     
        private void initComponents() {
     
         JLabel   jLabel1 = new JLabel();
          JPanel  jPanel1 = new JPanel();
     
          JButton  jButton1 = new JButton();
     
          JTextField  jTextField1 = new JTextField();
    		jPanel1.add(jLabel1);
    		jPanel1.add(jButton1);
    		jPanel1.add(jTextField1);
    		jPanel1.setVisible(true);
                    pack();
    		}
    public static void main(String args[])
    {		
            help h=new help();
    		h.initComponents();
     
    }
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Whats wrong with this it's not displaying inside component

    What is the variable name for the "inside component"?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Whats wrong with this it's not displaying inside component

    i did't use any variable

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Whats wrong with this it's not displaying inside component

    Please describe in more detail what happens when the program is executed.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    25
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: Whats wrong with this it's not displaying inside component

    You need to create a jframe and add the jpanel component to it. jpanel cannot be displayed on its own.
    so you can modify the code as

    JFrame jframe1 = new JFrame("NewFrame");
    frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE);
    JPanel jPanel1 = new javax.swing.JPanel();
    JLabel jLabel1 = new javax.swing.JLabel("how r u");
    JButton jButton1 = new javax.swing.JButton("yes");
    JTextField jTextField1 = new javax.swing.JTextField();
    JPanel1.setLayout(new FlowLayout());
    jPanel1.add(jLabel1);
    jPanel1.add(jButton1);
    jPanel1.add(jTextField1);
    jPanel1.setVisible(true);
    jframe1.add(jPanel1);
    jframe1.setSize(400,400);
    jframe1.setVisible(true);

    Hope this solves your problem

Similar Threads

  1. Replies: 4
    Last Post: January 10th, 2014, 05:25 AM
  2. Whats wrong?
    By help2 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 4th, 2012, 04:22 AM
  3. Whats wrong here?
    By Java Sucks in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 8th, 2011, 08:33 PM
  4. whats wrong with this one....
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 6th, 2009, 10:08 AM
  5. help whats wrong
    By silverspoon34 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 3rd, 2009, 01:41 AM