Re: Need help just inserting an image in a JPanel
On Feb 13, 9:33 am, "Jeff Higgins" <oohigg...@yahoo.com> wrote:
<mcan...@auburn.edu> wrote:
I want to know the quickest easiest way to insert an image in a JPanel
Here is my code so far
package graphingcalculator;
....
package graphingcalculator;
This is beginning to seem like a self contained
example based upon the OP's original code
(which I did not bother to compile, once
I understood 'load image'). So while I do
not have the overall understanding of this
code that someone might if they had compiled/
run it, I will point out one thing I noticed..
....
public class MainFrame extends JFrame {
....
public class PlotPanel extends JPanel{
...
public void paint(Graphics graphics) {
Swing components should overide
paintComponent(), rather than paint().
super.paint(graphics);
Graphics2D g = (Graphics2D)graphics;
// TODO Draw image here.
// See Andrews post.
(frowns) ..but while I am here, note that
my example did not need to overide paint,
and that if the OP *needs* to draw the image
from within paint(/Component) then it should
probably be loaded and cached once, with
the reference stored, and simply drawn
to screen each time paint() is called.
...and it is too late for me to think
straight, so I am going to bed.
Andrew T.