Solved

Adding repeating background to JFrame

Posted on 2008-06-17
7
1,071 Views
Last Modified: 2008-06-24
Hi,
I have a background image that I want to repeat to fill the JFrame.  How do I go about doing that?
With the code snippet below, the windows app is only the size of the actual image.  I know I don't have size dimensions set to make it bigger or anything, but if I specified the JFrame's size to be bigger, how would I make the background image repeat to fill the frame?
import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;
 

public class DavisPublishing 

{

	public JFrame conPanel;	

	

	public DavisPublishing(String title) 

	{

		conPanel = new JFrame();

		conPanel.setTitle(title);
 

		JLabel background = new JLabel(new ImageIcon("images/parchmnt.jpg"));

		conPanel.setContentPane(background);

		conPanel.getContentPane();

		conPanel.setLayout(new BorderLayout());

		conPanel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		

		conPanel.pack();

		conPanel.setVisible(true);

	}
 

   

   public static void main(String[] args)

   {

	   new DavisPublishing("Davis Publishing Company");

   }

}

Open in new window

0
Comment
Question by:P1ST0LPETE
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
I'm afraid you'd have to do your own tiling of the image i think. That means overriding paint/paintComponent
0
 
LVL 3

Accepted Solution

by:
Sankozi earned 500 total points
Comment Utility
I think the easiest solution is using HTML:
JEditorPane background = new JEditorPane();

background.setContentType("text/html");

background.setText(

     "<html><body style=\"background-image: url(http://www.google.com/intl/en_ALL/images/logo.gif);\"></body></html>");

conPanel.setContentPane(background);

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Much better. Pleasant surprise to see that css is supported
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
(i.e. that *particular* css)
0
 
LVL 10

Author Comment

by:P1ST0LPETE
Comment Utility
So I can use HTML in a standard Java app?  This program isn't web based at all.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Yes, most Swing components support html.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
Use the TexturePaint class, see the example here:

http://www.objects.com.au/java/qa/418590870.html
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Fibonacci challenge 11 81
bunnyEars2 challenge 6 65
countHi challenge 25 84
JAVA part two 5 39
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now