Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drawing in JPanel

 
Benjamin Ugbene
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50235
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2616
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob, will take a look at it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic