• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

Trying to put a jButton above an image

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Rancher
Posts: 3214
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No i tried both thought maybe there is a problem with jpgs but thats not it
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hint: Class#getResource(...) returns a URL.
 
twin yan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
A teeny tiny vulgar attempt to get you to buy our stuff
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic