Results 1 to 4 of 4
  1. #1
    seanfmglobal is offline Member
    Join Date
    Nov 2010
    Posts
    40
    Rep Power
    0

    Default JFrame needed for JPanel??

    Just curious if JFrame is needed if your trying to use JPanel..

    Java Code:
    public class TestPanel extends JPanel{
    Now somewhere after that do i need to make a new JFrame???

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,048
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by seanfmglobal View Post
    Just curious if JFrame is needed if your trying to use JPanel..

    Java Code:
    public class TestPanel extends JPanel{
    Now somewhere after that do i need to make a new JFrame???
    Yup, all applications can only display 'top level' components on your desktop; the Swing top level components are JFrame, JDialog and JWindow. You have to add your JPanel to one of these to be able to display it.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,143
    Rep Power
    10

    Default

    Yes. A JPanel is simply an area inside a window. You need to put that in a window. Whether that window is an JFrame or an Applet is up to you.

    Recommended reading: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

    Edit- Too slow. What Jos said.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  4. #4
    seanfmglobal is offline Member
    Join Date
    Nov 2010
    Posts
    40
    Rep Power
    0

Similar Threads

  1. jpanel in jframe-pls help
    By archanaanbu in forum Java Applets
    Replies: 3
    Last Post: 02-14-2011, 06:01 AM
  2. Jpanel and Jframe help!!
    By Java_n00b in forum AWT / Swing
    Replies: 4
    Last Post: 01-23-2011, 05:05 PM
  3. JFrame and JPanel
    By khiat in forum New To Java
    Replies: 6
    Last Post: 01-15-2011, 08:32 PM
  4. Help with JPanel and JFrame
    By weikang in forum AWT / Swing
    Replies: 3
    Last Post: 11-26-2010, 02:22 AM
  5. JPanel/JFrame
    By Mayur in forum New To Java
    Replies: 2
    Last Post: 12-20-2009, 06:07 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •