Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

How do I refresh the JFrame or call the paint method without calling initComponents()? :(  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make a program which calculates the distance between two points which the user gives by clicking on the JPanel. After the points are clicked, dots will be drawn on the points where the users clicked, lines will be drawn to mark the paths, and updates the appropiate JLabels using the Pythagorean theorem and Manhattan distance formulas.

The problem is how do I call my paintEntryPanel method with my graphics argument without having to call initComponents() all the time, because it screws up the display by placing components over each other. I've tried using setters to pass the graphics argument to a global variable, but that doesn't work. I've been taught to use a custom creation code on the JPanel, but I'm not really sure how or why it works and now I'm completely stuck on how to fix the code so I can separate the jPanel and draw function.
Any help would be greatly appreciated.


 
Sheriff
Posts: 21550
100
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just call repaint() on jPanel. This will call it's paint method which calls paintComponent which calls ep.paintEntryPanel.
 
Paul Nguyen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Prime wrote:Just call repaint() on jPanel. This will call it's paint method which calls paintComponent which calls ep.paintEntryPanel.



Oh my god, was that all I had to do? Thanks. It works now.
Now I just got to finish up the rest of the project. Thanks a bunch Rob!
 
Always look on the bright side of life. At least this ad is really tiny:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!