Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing objects  RSS feed

 
James Nobles
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot get my panels to appear in my GUI when I run my program. There is probably a really simple fix for this but it is taking me hours. This program is a working progress and I have just included two classes out of five. That should be adequate to diag my problem. Thanks for looking





 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I can see one problem. The deckPanel object (and it really should be DeckPanel - especially if you're then going to reuse that name as a variable) never has anything added to it. In its constructor you create another JPanel, confusingly also called deckPanel, and you add things to that, but you never add that to anything.

So I'd suggest losing the deckPanel variable in the deckPanel class, and add the components directly to that class.
 
James Nobles
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me get this straight. You are telling me to remove it from my class and then add it back to the same class? I am a novice
 
Campbell Ritchie
Sheriff
Posts: 55284
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our GUIs forum.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, a DeckPanel object IS already a JPanel. That's what it means to extend JPanel. (Sorry, I have to call it DeckPanel because otherwise it doesn't look like a class to me. You should do that too, as Matthew said.) So you don't need to create more DeckPanel objects inside it. Just use the one you're already constructing. (Remember, that's what the DeckPanel constructor does -- it constructs a DeckPanel object). So you want to add the components to the DeckPanel object you're constructing rather than to some other DeckPanel object. Like this:


 
James Nobles
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a ton sir. That was a easy fix.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!