RE: image ico
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi,
I want to add a image as a background on a panel i tried it by using ImageIcon icon = new ImageIcon("box.jpg");
JLabel iconl = new JLabel(icon);
but the panel consists of other components also like textfields. I am getting the image below the textfields when i added the JLabel. I actually want this image to be set as the complete background on which other components must be placed. Some body please help me to solve this.
Thanks & Regards
I want to add a image as a background on a panel i tried it by using ImageIcon icon = new ImageIcon("box.jpg");
JLabel iconl = new JLabel(icon);
but the panel consists of other components also like textfields. I am getting the image below the textfields when i added the JLabel. I actually want this image to be set as the complete background on which other components must be placed. Some body please help me to solve this.
Thanks & Regards
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
yes.i am only suggestion is instead of setting icon to Jlabel.make it one Jpanel and setback round as image..then add whatever we ant to add on this Jpanel.
like
leftPanel = new ImagePanel(imgPath + "final/left_bg.jpg"); //here path of he image
public class ImagePanel extends JPanel{
private Image img;
public ImagePanel(String img) {
this(new ImageIcon(img).getImage());
}
public ImagePanel(Image img)
{
this.img = img;
Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
setLayout(null);
}
public void paintComponent(Graphics g) {
g.drawImage(img, 0, 0, null);
}
}
like
leftPanel = new ImagePanel(imgPath + "final/left_bg.jpg"); //here path of he image
public class ImagePanel extends JPanel{
private Image img;
public ImagePanel(String img) {
this(new ImageIcon(img).getImage());
}
public ImagePanel(Image img)
{
this.img = img;
Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
setLayout(null);
}
public void paintComponent(Graphics g) {
g.drawImage(img, 0, 0, null);
}
}
Originally posted by adeeb alexander:
Hi,
I want to add a image as a background on a panel i tried it by using ImageIcon icon = new ImageIcon("box.jpg");
JLabel iconl = new JLabel(icon);
but the panel consists of other components also like textfields. I am getting the image below the textfields when i added the JLabel. I actually want this image to be set as the complete background on which other components must be placed. Some body please help me to solve this.
Thanks & Regards
Sk.Ashokkumar.....
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
You can do a lot with the painting. The code in Gregg's link and Ashok's post will scale (stretch) it to cover the entire panel. With some effort you can draw it any way you want, including tiled.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
| Can you shoot lasers out of your eyes? Don't look at this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |









