-1

im really stuck, i have to define the container object by associating it with the JFrame in order to get my JFrame working with all its components.

my code is follows:

// get content pane for attaching GUI components
  Container contentPane = getContentPane();

my JFrame i wish to call it billFrame, I also want to call my container billContentPane, so im looking for something like:

private JFrame billFrame = new JFrame();

Would the above code be correct, or what would i have to change? would an instance variable have to be declared or am i way off the mark?

Sean Collins
  • 25
  • 1
  • 8
  • `"i have to define the container object by associating it with the JFrame in order to get my JFrame working with all its components."` -- Sorry, but this is not clear to me at all, and if I'm understanding it at all doesn't seem to be necessary. What problems specifically are you having? Why not simply make your JFrame only when it is needed and not even subclassing JFrame. Most of us regular Swing coders **rarely** if ever subclass JFrame. – Hovercraft Full Of Eels Sep 12 '14 at 16:53
  • Well my JFrame isn't showing and it has to do with this, i believe i am not connecting the jFrame and container object properly, hence why i think my code needs to be changed – Sean Collins Sep 12 '14 at 16:54
  • Please describe your problem assuming that we can't see your code and don't know how your program is structured. You're still leaving things all unclear. – Hovercraft Full Of Eels Sep 12 '14 at 16:55
  • Problem is my code is all written but when i run it, no JFrame appears, im not sure why but i think its to do with the container and it not being properly coded to associate it with a jFrame – Sean Collins Sep 12 '14 at 16:57
  • I'll try this again. You're still asking your question as if we have some magic ability to see code not shown and to understand program structure not fully described. Most of us mortals, except for Jon Skeet and maybe MadProgrammer, don't have this ability. If you seriously are in need of help, then why not put some serious effort into your question, including describing **all** that is needed to understand your problem and showing code, preferably a [minimal compilable runnable example program](http://stackoverflow.com/help/mcve). – Hovercraft Full Of Eels Sep 12 '14 at 16:58
  • thanks but i got the answer and Hovercraft do us a favor, if you dont understand the question, then dont answer, ive explained what i wanted enough thank you – Sean Collins Sep 12 '14 at 17:01
  • 1
    Sean, this is a friendly place. People sacrifice their time to lend you a helping hand. Being impolite is a dead end. Were you more attentive you'd notice that Hovercraft has helped so many people in fixing Swing-related issues. Your question is vague and doesn't adhere to SO rules. Fix it and be nice in the future. – skuntsel Sep 12 '14 at 17:30
  • I'm glad that you've got the answer, and I'm glad that the answerer was good at guessing. Please understand that I was trying to get you to write a question that wouldn't require us to guess, that would give you a better chance of getting a correct and clean answer. Sorry that you took it wrong. – Hovercraft Full Of Eels Sep 12 '14 at 17:43
  • 1
    I'm sorry but i did explain what i was stuck on, but ill write the question in more detail the next time – Sean Collins Sep 12 '14 at 18:17

1 Answers1

3

You could do the following 2 things:

JFrame billFrame = new JFrame();
Container billContentPane = billFrame.getContentPane();

or

JFrame billFrame = new JFrame();
JPanel billContentPane = new JPanel();
bilFrame.setContentPane(billContentPane);

Of course you can have whatever identifiers you want [private or public].

Also as a note you should run these 2 commands to show your frame:

billFrame.pack();
billFrame.setVisible(true);
user2494817
  • 697
  • 4
  • 12