Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to put a jButton above an image  RSS feed

 
twin yan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ,
i'm trying to make a small game ,
i never done this before and got mixed up in the menus
i tried to make a background image and it worked
now i'm trying to put a jbutton on top of the background picture
and it won't show the button i'm guessing it's not on top
any ideas how to solve it ?

here's what i did to get the background image ( the rest is mostly netbeans auto)



thanks to all helpers
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another way is to use a Jpanel to paint the image as its background, then add components as normal

here's a very simple demo
(the BackgroundPanel class is from this forum's FAQ (main page))

 
twin yan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i tried it this way but when i run it , it doesn't show the background picture
and in the exception it's saying

java.net.MalformedURLException: no protocol: images/c.gif

any ideas why or what that means ?
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your original code you where using "image/c.jpg". Maybe the message is saying it can't find the "c.gif"?
 
twin yan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No i tried both thought maybe there is a problem with jpgs but thats not it
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: Class#getResource(...) returns a URL.
 
twin yan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
been sitting on it for hours , still no idea

now it's saying :

java.lang.IllegalArgumentException: input == null!

i tried


and



both doing the same input == null!
the folder and file name is correct
any ideas ??
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
go back to my demo code and run it again, replacing *all* occurrences of "Test.gif" with
"images\\c.jpg"
not
"images/c.jpg"

remember it's *all* occurrences
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!