hi everyone!
i am using bluej and i want to set a photo as my background by using imagePanel, i think. However, i don't know how to do. can someone help me out giving some code for this as an example. thanks alot.
5 4043 BigDaddyLH 1,216
Recognized Expert Top Contributor
hi everyone!
i am using bluej and i want to set a photo as my background by using imagePanel, i think. However, i don't know how to do. can someone help me out giving some code for this as an example. thanks alot.
I am not familiar with "imagePanel". What framework are you using?
I am using 'JFrame' and i would like to know how to use ImagePanel, ImageFileManager, OFImage and ImageViewer to set photo as a background of a GUI.
JosAH 11,448
Recognized Expert MVP
I am using 'JFrame' and i would like to know how to use ImagePanel, ImageFileManager, OFImage and ImageViewer to set photo as a background of a GUI.
I only know of JFrame being a class in the core set of Java SE classes; are all
the Image* classes your own or from a third part library? If so you need to consult
their API documentation for their use because they are not part of the Java SE
core library.
kind regards,
Jos
BigDaddyLH 1,216
Recognized Expert Top Contributor
I am using 'JFrame' and i would like to know how to use ImagePanel, ImageFileManager, OFImage and ImageViewer to set photo as a background of a GUI.
What framework is ImagePanel, ImageFileManager, OFImage and ImageViewer in?
BigDaddyLH 1,216
Recognized Expert Top Contributor
There are a number of ways to get a background image. My favourite way is a bit of a cheat, since I define a Border that draws the image. I like this approach since it doesn't involve subclassing any JComponent type. - import java.awt.*;
-
import java.awt.image.*;
-
import javax.swing.border.*;
-
-
public class CentredBackgroundBorder implements Border {
-
private final BufferedImage image;
-
-
public CentredBackgroundBorder(BufferedImage image) {
-
this.image = image;
-
}
-
-
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
-
int x0 = x + (width-image.getWidth())/2;
-
int y0 = y + (height-image.getHeight())/2;
-
g. drawImage(image, x0, y0, null);
-
}
-
-
public Insets getBorderInsets(Component c) {
-
return new Insets(0,0,0,0);
-
}
-
-
public boolean isBorderOpaque() {
-
return true;
-
}
-
}
-
- import java.awt.*;
-
import java.io.*;
-
import java.net.URL;
-
import javax.imageio.*;
-
import javax.swing.*;
-
import javax.swing.border.*;
-
-
public class BackgroundBorderExample {
-
public static void main(String[] args) throws IOException {
-
JFrame.setDefaultLookAndFeelDecorated(true);
-
JFrame f = new JFrame("BackgroundBorderExample");
-
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
JTextArea area = new JTextArea(24,80);
-
area.setForeground(Color.WHITE);
-
area.setOpaque(false);
-
area.read(new FileReader(new File("BackgroundBorderExample.java")), null);
-
final JScrollPane sp = new JScrollPane(area);
-
sp.setBackground(Color.BLACK);
-
sp.getViewport().setOpaque(false);
-
f.getContentPane().add(sp);
-
f.setSize(600,400);
-
f.setLocationRelativeTo(null);
-
f.setVisible(true);
-
-
String url = "http://blogs.sun.com/jag/resource/JagHeadshot.jpg";
-
final Border bkgrnd = new CentredBackgroundBorder(ImageIO.read(new URL(url)));
-
Runnable r = new Runnable() {
-
public void run() {
-
sp.setViewportBorder(bkgrnd);
-
sp.repaint();
-
}
-
};
-
SwingUtilities.invokeLater(r);
-
}
-
}
-
In the above example (where orange really isn't my best colour) I used the JScrollPane method setViewportBorder. For other containers, you typically use setBorder.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: DexHex |
last post by:
Hi,
I am stumpt. Is there anyway to set the background image on a webpart
title?
|
by: Sam |
last post by:
Hi all
I'm looking for a way to detect the background color of my internal webpage
through a stylesheet. And so far, the only solution I find is to open the
styles.css file and parse the...
|
by: laredotornado |
last post by:
Hi,
I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed
using Apache's apxs and the php library was installed to
/usr/local/php. However, when I set my "error_reporting"...
|
by: mi0sis |
last post by:
Right now I am currently using this:
------------------------------------------------------------
.div0 {
background-image:url(http://www.rubnip.com/Pictures/topback.gif);...
|
by: david.karr |
last post by:
If in my CSS I set the "background-color" property on the "body"
element, it only covers the background of the elements defined in the
body, up to the current width and height of the page. However,...
| |
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |