• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

JPanel Visible.

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Simply, why the JPanel is not visible when running this. Nothing appears and there are no errors.

Thanks
 
Marshal
Posts: 80874
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I shall have to transfer this thread to Swing, since it is a GUI-related topic.

You can't display a panel on its own; it has to be added to a container, of which the most popular type is the JFrame.

You are also supposed to start a new thread; the details are in the API for any Swing class, where the link to "Swing threading policy" is.

You need to do three things to make a frame appear properly
  • Give it a size
  • Decide what to do when it closes; I think the default is "hide." You can set a default for closing; EXIT closes the entire JVM. Or you can use a Listener, but that is too advanced for you.
  • Set it visible. Do this last.
  • That ought to work. Needless to say there are several different versions of setting up a Frame like that. You will have to check in the API for JFrame; I am pretty certain I have spelt setDefaultClosingOperation wrongly.

    And good luck with it.
     
    Bartender
    Posts: 1561
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The best recommendation for you is to start going through the Sun Swing tutorials. This will teach you how to do Swing coding the right way from the get-go. You won't regret doing this, trust me.
     
    Campbell Ritchie
    Marshal
    Posts: 80874
    506
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I agree that the Java Tutorial is usually a good place to start for almost anything.

    I managed to move this thread just at the same time that a newbie was posting a possible answer (here), which he added as a new thread in beginner's. I had to close the new thread because we can't have two halves to a conversation, but it is still worth a look.
    [edit]Corrected the link[/edit]
    [ December 07, 2008: Message edited by: Campbell Ritchie ]
     
    Ranch Hand
    Posts: 147
    Android Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sorry about the confusion....and thanks for the welcome!
    I agree the Swing tutorial is a great place to start.
    The Bunkhouse is another.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic