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
    13,663
    Blog Entries
    7
    Rep Power
    21

    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
    cenosillicaphobia: the fear for an empty beer glass

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

    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 - Play indie games, learn from game tutorials and source code, upload your own games!

  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, 05:01 AM
  2. Jpanel and Jframe help!!
    By Java_n00b in forum AWT / Swing
    Replies: 4
    Last Post: 01-23-2011, 04:05 PM
  3. JFrame and JPanel
    By khiat in forum New To Java
    Replies: 6
    Last Post: 01-15-2011, 07:32 PM
  4. Help with JPanel and JFrame
    By weikang in forum AWT / Swing
    Replies: 3
    Last Post: 11-26-2010, 01:22 AM
  5. JPanel/JFrame
    By Mayur in forum New To Java
    Replies: 2
    Last Post: 12-20-2009, 05: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
  •