🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.api
2 messages
2 total messages Started by Scott Wells Tue, 01 Apr 2003 19:00
Background image not showing up in Designer
#658
Author: Scott Wells
Date: Tue, 01 Apr 2003 19:00
25 lines
1489 bytes
Hello, I've placed a panel on my applet form and wanted to add a
background to it so I can place components (buttons, etc) at
appropriate spots on the image.

I can get the image to show up during run time, but not at design
time. To get the  image as a background, I did the following:

public class UFTApplet extends Applet {
  Panel panel2 = new Panel()
  {
    public void paint(java.awt.Graphics g)
    {
           Image bkgd = getImage(getCodeBase(), "desaltemplate.jpg");

           super.paint(g);
           g.drawImage(bkgd, 0, 0, this);
    }
  };

How can I get the designer to load the image so I can place components
on it?

Thank you.

Scott
Re: Background image not showing up in Designer
#659
Author: Scott Wells
Date: Tue, 01 Apr 2003 23:28
90 lines
2940 bytes
Okay, I got a bit further. I created a new panel class that extends
JPanel:

import java.awt.*;
import javax.swing.JPanel;

public class UFTPanel extends JPanel
{
  private Image image = null;
  public UFTPanel()
  {
  }

  public UFTPanel( Image image )
  {
    this();
    setImage( image );
    this.repaint();
  }

  public Image getImage()
  {
    return image;
  }

  public void setImage( Image newImage )
  {
    this.image = newImage;
  }

  public void paint( Graphics g )
  {
    if (image != null)
    {
      g.drawImage(image, 0, 0, this);
    }
  }
}
-----

Now, in my applet, I have:
    Image bkgd = null;

 bkgd = getImage(new
URL("file:/home/swells/UFT/UFTJavaProject/classes/desaltemplate.jpg"));
 panel2.setImage(bkgd);
----
During run time, the image shows up fine, but during desing time, when
I switch to the Design tab, I get the following error: 'null invoking
getImage(new URL("file:/home/swells/UFT/UFTJavaProject/classes/desaltemplate.jpg"));'

I'm at my wits end here. I don't understand why the picture isn't
showing up.
I tried using getCodeBase(), but I got: 'null invoking getCodeBase()'.

Please, any suggestions?

Thanks,

Scott




swells@merxyn.com (Scott Wells) wrote in message news:<86952eb4.0304011100.551a5b5d@posting.google.com>...
> Hello, I've placed a panel on my applet form and wanted to add a
> background to it so I can place components (buttons, etc) at
> appropriate spots on the image.
> 
> I can get the image to show up during run time, but not at design
> time. To get the  image as a background, I did the following:
> 
> public class UFTApplet extends Applet {
>   Panel panel2 = new Panel()
>   {
>     public void paint(java.awt.Graphics g)
>     {
>            Image bkgd = getImage(getCodeBase(), "desaltemplate.jpg");
> 
>            super.paint(g);
>            g.drawImage(bkgd, 0, 0, this);
>     }
>   };
> 
> How can I get the designer to load the image so I can place components
> on it?
> 
> Thank you.
> 
> Scott
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads