Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Wiki
Search Coderanch
Advance search
Google search
Register / Login
Bookmark Topic
Watch 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
Forums:
Wiki
Swing / AWT / SWT
Background Image On JPanel
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
How do I paint an image as a background on a JPanel?
This question gets asked quite frequently in the Swing forum. There are different methods of doing this however this is the simplest and most common.
class BackgroundPanel extends JPanel { Image image; public BackgroundPanel() { try { image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("Test.gif"), "Test.gif")); } catch (Exception e) { /*handled in paintComponent()*/ } } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (image != null) g.drawImage(image, 0,0,this.getWidth(),this.getHeight(),this); } }
SwingFaq
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
No progress...help
Trying to put a jButton above an image
how to make an image my jpanel background
What the heck!? JPanel background problem - weird!
Glass panes -- transparent panes
More...