File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Drawing in JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Drawing in JPanel" Watch "Drawing in JPanel" New topic
Author

Drawing in JPanel

Benjamin Ugbene
Greenhorn

Joined: Sep 29, 2004
Posts: 9
Hello,

I must start by saying that I'm not entirely sure if this is the right section to post this question.

With that taken care of, now for my question. I am trying to set up a Java Desktop Application using net beans. It requires that I do some drawing; hence, fromsurfing the web, is discovered that most people draw on Jpanels. I am currently trying to draw on a JPanel, but this has proved abortive. 99% of the examples I see online are for Applets, I have tried to extract what I can, but this has not helped me. I have tried using both Graphics, and Graphics2D components, still nothing. Can anyone please rescue me...PLEASE!!!

Cheers.



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Benjamin Ugbene wrote: . . . I'm not entirely sure if this is the right section to post this question. . . .
I'm not sure either; I shall move it to our GUIs forum.

Please tell us more details. What happens when you execute your code? What are you planning to draw? Is it drawing in the program or drawing from user input in real-time? Have you got a book? Have you seen the Java™ Tutorials? (There are other Java™ Tutorials sections you may also find useful.
Benjamin Ugbene
Greenhorn

Joined: Sep 29, 2004
Posts: 9
Please tell us more details. What happens when you execute your code? What are you planning to draw? Is it drawing in the program or drawing from user input in real-time?


Thanks for your reply. Well for now I am still testing, eventually, the users will set certain parameters, which will be used to draw at run-time as they vary parameters.

Currently when it runs nothing is drawn in the JPanel.

Cheers.
dziubut dziubucinski
Greenhorn

Joined: Sep 14, 2010
Posts: 8
Imho - in 90% if nothing is painted then its problem with layout (but im not sure). I dont like netbeans becouse of little mess with code...
Can you show initComponents() method? (its auto-generated right?)
Benjamin Ugbene
Greenhorn

Joined: Sep 29, 2004
Posts: 9
Thanks all, but I found a solution on YouTube

Painting with java.awt on a JPanel in a Desktop Application Java

Cheers.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2227
    
    8
I find the Swing tutorial are the best place to start so you don't have to search all over the internet.

In this case you can start with the section on Custom Painting.

I also try to provide a brief summary with working examples in Custom Painting Approaches.
Benjamin Ugbene
Greenhorn

Joined: Sep 29, 2004
Posts: 9
Thanks Rob, will take a look at it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Drawing in JPanel