Hello, I was wondering how do I draw objects on a JFrame and not a JPanel, because whenever I search google it always comes up with ways to draw it on a JPanel.
Printable View
Hello, I was wondering how do I draw objects on a JFrame and not a JPanel, because whenever I search google it always comes up with ways to draw it on a JPanel.
Why would you want to draw directly on the JFrame and not on the JPanel? If we knew your rationale for going against standard practice, perhaps we could help you better.
Which part of the JFrame do you plan on drawing on? The content pane? root pane? glass pane? layered pane? Do you know the reasons why the google search is giving you this answer, why it is in general a very bad idea to draw directly on the JFrame?
Why on earth do you want to paint directly on the frame?
Then you're doing something wrong, but the solution is not to do something even more wrong such as drawing directly on the JFrame as this won't fix your current problem and will add a heap of other new problems. No the solution is to continue drawing on the JPanel and to figure out why your program has the error and fix it.
This is likely due to your needing to understand which layout manager(s) is/are being used and how to best add the JPanel to its container so that it will be best visualized. Most layout managers don't listen to the JPanel's size but often do respect its preferredSize. You may wish to try setting the JPanel's preferredSize via setPreferredSize(new Dimension(....)), and then revalidating and repainting the container that you're adding the JPanel to.
I strongly urge you to create a small compilable runnable program that we can run, test, modify ourselves, that requires no outside dependencies such as images on disk or database, in short, an SSCCE, and then post the code here and we can help you with it.
Cool. Glad you've got it working, and I wish all advice were so easy to give.
That request was for our benefit not yours. You really have a lot to learn about how to get help. In a previous thread I requested you post your error messages and your response was "Nah! You don't need to see them". If you do not provide us will adequate and accurate information then there is not a snowballs chance in hell of anyone being able to help you.
It benefits me and everyone else if you improved the quality and quantity of information in your posts. The benefit is that it doesn't take 20 posts of back and forth of extracting information from you before we get to the real problem. If you post all the information in your first post then it will be a lot easier for us to diagnose the problem and provide a solution. The follow on effect is that you get a response sooner so you can fix your problem.
Whooooooooooooooosh!