Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JPanel Visible.  RSS feed

 
Brian Lemieux
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

Thanks
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • 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.
     
    pete stein
    Bartender
    Posts: 1561
    • Mark post as helpful
    • send pies
    • 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: 55672
    161
    • Mark post as helpful
    • send pies
    • 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 ]
     
    Glen Tanner
    Ranch Hand
    Posts: 147
    Java Python Ruby
    • Mark post as helpful
    • send pies
    • 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.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!