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: extended JPanel is empty

  1. #1
    Member
    Join Date
    Sep 2011
    Posts
    46
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default extended JPanel is empty

    Hi,
    I made a extended JPanel, but when i call on it in another class the panel shows but its empty... This is my code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class FindPanel extends JPanel
    { 
        JRadioButton biologyClass = new JRadioButton("Biology");
        ...make a radiobutton for each subject
     
        ButtonGroup classButtonGroup = new ButtonGroup();
        public void classesJPanel() {
            //add to button group
            classButtonGroup.add(biologyClass);
            ... add all the subjects to buttongroup
            //add to panel
            add(biologyClass);
            ...add all the subjects
            }
     
     
     
    }

    when i call on the code this is what i am using:
    FindPanel jPanel1 = new FindPanel();

    Thanks
    Joel


  2. #2
    Member
    Join Date
    Sep 2011
    Posts
    46
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: extended JPanel is empty

    I should also point out that im trying to call it in an applet. I called it in a normal JFrame and it worked fine, it just doesnt like the applet...

  3. #3
    Member
    Join Date
    Aug 2011
    Posts
    55
    Thanks
    5
    Thanked 3 Times in 3 Posts

    Default Re: extended JPanel is empty

    You do not have a constructor for your FindPanel Class. You need an overide constructor

  4. #4
    Member
    Join Date
    Sep 2011
    Posts
    46
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: extended JPanel is empty

    How do i make an override constructor? What is it exactly?

  5. #5
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: extended JPanel is empty

    JPanel is your superclass, in this case, so you need to insert the code...
    super(String title)
     
    //title is what the dialog box will be named in its title bar
    ...before your other code.

    You also need to surround everything you have so far except the class name in...
    public FindPanel() {
    //your other code here
    }

    So, when it's all put together, the end result should be something like this:
    public class FindPanel extends JPanel
    {
       public FindPanel()
       {
     
          super(String title)
          //Note that you will not actually type "String title"; instead you
          //should type what you want the dialog to be titled when you open it
     
          //Put all your other code here, like the JRadioButton and ButtonGroup, etc.
          //Don't include the "public void classesJPanel()" part, just remove those brackets
          //The "super" constructor already creates a JPanel, and you're just customizing it
     
       }
    }
    Hopefully I got my meaning through... Sorry if it's unclear.
    Last edited by snowguy13; November 26th, 2011 at 05:43 PM. Reason: To increase clarity

Similar Threads

  1. Replies: 1
    Last Post: September 21st, 2011, 01:05 AM
  2. Extended Hanooi Tower
    By mahsa in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 31st, 2010, 05:55 PM
  3. Imitating a JFrame extended program with JPanel; help needed...
    By emigrant in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 15th, 2010, 02:30 PM
  4. How to copy image from one jpanel to another jpanel
    By ramanavarayuri1986 in forum AWT / Java Swing
    Replies: 0
    Last Post: February 15th, 2010, 02:36 AM
  5. Creating and displaying a JPanel inside another JPanel
    By JayDuck in forum AWT / Java Swing
    Replies: 1
    Last Post: April 7th, 2009, 08:02 AM