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 How do I refresh the JFrame or call the paint method without calling initComponents()? :( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How do I refresh the JFrame or call the paint method without calling initComponents()? :(" Watch "How do I refresh the JFrame or call the paint method without calling initComponents()? :(" New topic
Author

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

Paul Nguyen
Greenhorn

Joined: Nov 02, 2010
Posts: 6
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.


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Nguyen
Greenhorn

Joined: Nov 02, 2010
Posts: 6
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I refresh the JFrame or call the paint method without calling initComponents()? :(