You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by Dwayne Murphy <dw...@wecdsb.on.ca.INVALID> on 2023/03/10 03:05:52 UTC

Problem adding an image to a label icon...

Hi everyone,

I have a simple project in java / maven  in apache netbeans.

I have a JFrame with a label that I have been trying to add an image to.

I continually get this error when the program tries to add the image to the
label:

*Cannot invoke "java.net.URL.toExternalForm()" because "location" is null*


I have tried using the image selector, as well as custom code options. I
have tried all the advice from stack overflow --- and I simply can't figure
it out. I must have spent 3-4 hours --- and I'm about to give up.

Can anyone tell me why its so difficult to add an image to a JFrame?  Is
there a simple way to do it? Am I missing something?

PS: This link seems to be a great resource for my problems... but I'm still
getting the error!
https://netbeans.apache.org/kb/docs/java/gui-image-display.html


-- 

Dwayne Murphy
"Carpe Diem"
Hons B.Computer Science, B. Ed, Hons B.Commerce
Holy Names High School - Science, Business & Civics

Holy Names: 519-966-2504
Cell Number: 519-995-6915

Re: Problem adding an image to a label icon...

Posted by Tim de Vries <te...@gmail.com>.
Hi,

If you trace through paint(Graphics g) and paintComponent(Graphics g), 
it shows what code is executed and when. You may also want to trace 
doLayout() if writing custom layout code. Don't forget 
super.methodName(params) or you may not activate the events for the 
specific thing you are doing, whether event processing or painting.

You may use: tecreations.ca/java/downloads/release/tecreations-0.4.0.jar 
to facilitate your os/network/image/text operations. That jar contains 
many examples of using the Swing and AWT classes together for whatever 
you need.

Of particular interest may be: CaptureTool, Deploy, Launcher? 
SystemCompiler for SystemTray use?

It should launch with double-click on Windows or 'java -jar 
tecreations-0.4.0.jar'. Run the Launcher, go from there.


Tim


On 2023-03-09 8:05 p.m., Dwayne Murphy wrote:
> Hi everyone,
>
> I have a simple project in java / maven  in apache netbeans.
>
> I have a JFrame with a label that I have been trying to add an image to.
>
> I continually get this error when the program tries to add the image 
> to the label:
>
> *_Cannot invoke "java.net.URL.toExternalForm()" because "location" is 
> null_*
>
>
> I have tried using the image selector, as well as custom code options. 
> I have tried all the advice from stack overflow --- and I simply can't 
> figure it out. I must have spent 3-4 hours --- and I'm about to give up.
>
> Can anyone tell me why its so difficult to add an image to a JFrame?  
> Is there a simple way to do it? Am I missing something?
>
> PS: This link seems to be a great resource for my problems... but I'm 
> still getting the error!
> https://netbeans.apache.org/kb/docs/java/gui-image-display.html
>
>
> -- 
>
> Dwayne Murphy
> "Carpe Diem"
> Hons B.Computer Science, B. Ed, Hons B.Commerce
> Holy Names High School - Science, Business & Civics
>
> Holy Names: 519-966-2504
> Cell Number: 519-995-6915

Re: Problem adding an image to a label icon...

Posted by Admin Netcrystals <ad...@netcrystals.at.INVALID>.
I think the location to your image is incorrect.

Where do you store your image and what is the url pattern?

Do you use Matisse builder to add the image to the label or do you do it
programmatically?

  

Netcrystals



* * *

 **Von:** Dwayne Murphy <dw...@wecdsb.on.ca.INVALID>  
 **Gesendet:** Freitag, März 10, 2023 4:07 AM  
 **An:** users@netbeans.apache.org <us...@netbeans.apache.org>  
 **Betreff:** Problem adding an image to a label icon...



Hi everyone,

  

I have a simple project in java / maven  in apache netbeans.

  

I have a JFrame with a label that I have been trying to add an image to.

  

I continually get this error when the program tries to add the image to the
label:

  

 ** _Cannot invoke "java.net.URL.toExternalForm()" because "location" is
null_**  

  

  

I have tried using the image selector, as well as custom code options. I have
tried all the advice from stack overflow --- and I simply can't figure it out.
I must have spent 3-4 hours --- and I'm about to give up.

  

Can anyone tell me why its so difficult to add an image to a JFrame?  Is there
a simple way to do it? Am I missing something?

  

PS: This link seems to be a great resource for my problems... but I'm still
getting the error!

<https://netbeans.apache.org/kb/docs/java/gui-image-display.html>  

  

  

\--  

  

Dwayne Murphy  

"Carpe Diem"

Hons B.Computer Science, B. Ed, Hons B.Commerce

Holy Names High School - Science, Business & Civics

  

Holy Names: 519-966-2504  

Cell Number: 519-995-6915  

\--------------------------------------------------------------------- To
unsubscribe, e-mail: users-unsubscribe@netbeans.apache.org For additional
commands, e-mail: users-help@netbeans.apache.org For further information about
the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists