Jpg Images as table background
Help. I keep finding that the images that I have set as a
background to a table or a cell in Dreamweaver MX does not appear
online when I publish the site. What am I doing wrong?
Text
The background image has been applied to a <tr>?
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com
- Template Triage!
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
http://www.macromedia.com/support/search/
- Macromedia (MM) Technotes
==================
"Osgood" <[email protected]> wrote in
message
news:ee64an$if0$[email protected]..
> Dolcie wrote:
>
>> Help. I keep finding that the images that I have set
as a background to
>> a table or a cell in Dreamweaver MX does not appear
online when I publish
>> the site. What am I doing wrong?
Text
>
> For anyone to really help out we would need to see your
page. can you
> upload it and give a link?
>
> If you can do that Im sure someone will be able to point
you in the right
> direction.
>
> There maybe a number of reasons why the image doesnt
appear, the simplest
> being the image has not been uploaded or the image has
been uploaded in
> the wrong place.
>
Similar Messages
-
Jpg images have gray background
I am using Fireworks from CS3 and for some reason when I export an image as a jpg, the resulting image has a faint gray background, instead of being pure white as I had intended. How do I stop this from happening?
I had this happen as well using CS5. Is there a way to preavent this please?
-
Superimposed jpg image comes with unwanted background
hi.
I cut out an object from a jpg image and made a new jpg image with transparent background. Tested it on image editing program - the background is indeed transparent.
However, when i try to superimpose the image with transparent background on a video in PrE, the image is shown with a white background.
How do i remove that unwanted white background?Great news!
In many Image editors, Transparency is not clearly deliniated, and it just looks white. With display settings in Photoshop, Transparency will be shown as a checkerboard pattern, but when one does a Save_As to JPEG, that clearly goes white, alerting the user to the lack of Transparency in the JPEG.
Good luck, and happy editing.
Hunt
PS - When you get your plane crashing into the tree, please post a link to YouTube, Vimeo, etc., so that we can see it. -
How can I load a gif or jpg in a JFrame (background)
I wanna load a gif or jpg image as a background at a JFrame. How can do this?
ThanksI have tried that but my image always paints over the swing components. Could you give more a code snippet?
-
Stop Background Image in Table from Repeating
Since CS4 has unfortunately removed the button for Background Image for tables, I found a neat work-around on the internet: select the cell, then open the Tag Inspector panel, select the Attributes button and Show list view, and click inside "background" and use the folder icon to navigate to the background image. However, I can't stop the image from repeating. I've tried everything I can think of. Can anyone help me? No code responses, please. Thanks!
monelleny wrote:
Can anyone help me?
Yes.
No code responses, please. Thanks!
Well, in that case, the answer is no.
Quite honestly, if you're capable of searching for an answer on the internet, and using the Tag Inspector to add a background image, you should be capable of following simple instructions to handle CSS.
To add a non-repeating background image to a table cell (or any element, for that matter), you use CSS. Create a CSS class like this in the head of the page:
<style type="text/css">
.background {
background-image: url(images/bg.jpg);
background-repeat: no-repeat;
</style>
Select the table cell, and then choose background from the Class menu in the Property inspector. -
Background Image In Table Cell
I'm not sure what I'm doing wrong or missing here. This is the first time that I'm using an image as a background. I've made a table with a 100% width with 3 colums and 3 rows. The left and right table cells have been merged and the 3 middle rows are at a width of 938 pixels. I have cropped the images correctly. The right column lines up perfectly, but the left column does not line up like it's supposed to with the image. You can take a look at it by going to http://www.wattsconcepts.com/new
Here is the code below if anyone wants to take a look at it. Any help in solving this is greatly appreciated. I am using Dreamweaver CS5.5
Thank you for your time!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Watts Concepts - Kentucky Web Design - Harrodsburg, Kentucky</title>
<style type="text/css">
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #000;
background-image: url();
</style>
</head>
<body>
<table width="100%" align="center" cellpadding="0" cellspacing="0">
<tr>
<td rowspan="3" align="left" valign="top" background="images/left-index.jpg"> </td>
<td width="938" align="center" valign="top"><img src="images/logo-index.jpg" width="938" height="172" /></td>
<td rowspan="3" align="left" valign="top" background="images/right-index.jpg"> </td>
</tr>
<tr>
<td align="center" valign="top"><img src="images/eye-index.jpg" width="938" height="296" alt="Reach Your Audience Today" /></td>
</tr>
<tr>
<td align="center" valign="top"><img src="images/test-index.jpg" width="938" height="197" /></td>
</tr>
</table>
</body>
</html>Your HTML code should ideally be as follows:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Watts Concepts - Kentucky Web Design - Harrodsburg, Kentucky</title>
<style type="text/css">
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #000;
</style>
</head>
<body>
<table width="938px" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="938" align="center" valign="top"><img src="images/logo-index.jpg" width="938" height="172" /></td>
</tr>
<tr>
<td align="center" valign="top"><img src="images/eye-index.jpg" width="938" height="296" alt="Reach Your Audience Today" /></td>
</tr>
<tr>
<td align="center" valign="top"><img src="images/test-index.jpg" width="938" height="197" /></td>
</tr>
</table>
</body>
</html>
Also, you don't need 3 columns for this website. 1 column and 3 rows should do. Also, never use 100% for <table> width. It's bad practice as you're making your site fluid which will render your site to malfunction on some browsers
And you had the entire 3 sections as 1 image as your CSS body background-image. This is bad practice. Crop only what you want for each section, never give the entire merged site as 1 image.
Try the code I've given you above and it should work perfect.
A quick tip: Try learning and using DIV with pure CSS styling instead of tables. Tables are a thing of the past. You could just google it and you have tons of free resources on how to create a site using DIV. Also, there's a beautiful tutorial posted by one of our senior members here: http://www.adobe.com/devnet/dreamweaver/articles/dw_html5_pt2.html that explains how to create HTML5 site with Pure CSS styling using DIV tags.
Cheers,
ST -
Stopping tiling in a table background image
I'm trying to stop the tiling of the background image within
a table in Dreamweaver 8.
It seems to be different then "no-repeat" for the general
background.
Was hoping someone could help me out.
Thanks.You have no tiling control there at all.
Change this -
<table width="612" height="1081" border="0"
background="ess_web_ad_bg.jpg">
to this -
<table width="612" height="1081" border="0"
background="ess_web_ad_bg.jpg"
style="background-repeat:no-repeat;">
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com
- Template Triage!
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
http://www.macromedia.com/support/search/
- Macromedia (MM) Technotes
==================
"Ro-Dogg" <[email protected]> wrote in
message
news:[email protected]...
> THANKS!
>
>
>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
> "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="
http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
> <title>Untitled Document</title>
> <style type="text/css">
> <!--
> .style1 {
> font-size: 12px;
> font-weight: bold;
> }
> .style2 {font-size: 12px}
> .style4 {font-size: 18px; font-weight: bold; }
> -->
> </style>
> </head>
>
> <body>
> <table width="612" height="1081" border="0"
> background="ess_web_ad_bg.jpg">
> <tr>
> <td width="21" height="143"> </td>
> <td width="557"> </td>
> <td width="20"> </td>
> </tr>
> <tr>
> <td height="294"> </td>
> <td rowspan="3" valign="top"> <div
class="style4"><span
> styleclass="style_HeadlineText">Are Your Employees a
Road
> Block?</span></div>
> <div class="style2"><span
>
styleclass="style_HeadlineText"> </span></div>
> <span class="style2"
styleclass="style_HeadlineText">
Did You Know
> That</span>
> <ul class="style2">
>
10%-12% of all applicants have a criminal history
> </li>
>
43% of resumes contain significant inaccuracies about
> experience, education or job ability </li>
>
8.5% of applicants who authorized background checks had
> criminal convictions</li>
>
> <div class="style2">
> <div>
The potential costs and liabilities of
unscreened or
>
insufficiently screened employees are enormous. Employers
can be
> held
> legally and financially responsible for things they
should have known
> about
> their employees.</div>
> </div>
>
> <li class="style2">
Employers lose 79% of all negligent hiring and
> retention lawsuits </li>
> <li class="style2">
Two-thirds of negligent hiring trials result
> in
> average awards of $600,000 in damages </li>
> <li class="style2">
30% of all business failures are caused by
> employee theft </li>
> <li class="style2">
The Small Business Administration estimates
> that
> for every dollar invested in employee screening a $5 to
$16 return is
> generated</li>
>
> <p align="center" class="style1"><span
> styleclass="style_SubheadingText">FOLEY SERVICES INC.
PROVIDES
> COMPREHENSIVE
> EMPLOYEE SCREENING SERVICES TO BUSINESSES OF ALL
SIZES</span></p>
> <div class="style2">
> <div>
We can conduct specific individualized background checks
> in
> all of the areas listed below, or provide screening
service packages
> tailored
> to your needs. </div>
> </div>
> <li class="style2">
Criminal Records Checks: Patriot Act
> Inquiry,
> Sex Offender Registry, Federal and Non-Federal criminal
history checks
>
> </li>
> <li class="style2">
Background and Reference Checks:
> Verification of
> Employment, Education, Reference, Social Security
Numbers, and
> Professional
> credentials </li>
> <li class="style2">
Motor Vehicle Reports </li>
> <li class="style2">
Financial/Healthcare Sanction
> Checks</li>
>
> <span styleclass="style_SubheadingText">
> <p align="left" class="style2">Foley Services has
a 15-year track
> record
> of servicing our client's with professionalism, courtesy
and respect.
> Let
> Foley Services put our expertise and experience to work
for you by
> helping
> you hire the right people for the job.</p>
> </span>
> <div align="center"> </div>
> <div align="center">
Click on the link below for further detailed
> information.<br />
>
<a href="
http://www.foleyservices.com/t-ebc_facts.aspx">FOLEY
> SERVICES EMPLOYMENT SCREENING
SERVICE</a></div>
> <div align="center"> </div> <div
align="center">
or
> Contact:<br />
>
Kirk Spooner<br />
> National Accounts Representative<br />
>
1-800-253-5506 x469
<br />
> <a
>
href="mailto:[email protected]">[email protected]</a></div></td>
> <td> </td>
> </tr>
> <tr>
> <td height="204"> </td>
> <td> </td>
> </tr>
> <tr>
> <td> </td>
> <td> </td>
> </tr>
> <tr>
> <td height="191"> </td>
> <td> </td>
> <td> </td>
> </tr>
> </table>
> </body>
> </html>
>
> -
Repeating background images in tables
I am working on a web page with a background image in a
table. I have also inserted a table inside this same table to
include some text. When I preview this in Netscape/Firefox and
increase the text size a couple of times from the browsers menu,
the table with the image starts repeating as the text increases in
size. I don't mind the text changes sizes, but is there a way to
stop the table from repeating the background image? This is a
problem since the repeating image looks terrible.On that page, change this -
</head>
to this -
<style type="text/css">
table.special { background-repeat:no-repeat; }
</style>
</head>
and then change your table tag from this -
<table width="100%" height="606" border="0" align="center"
cellpadding="0"
cellspacing="0">
to this -
<table width="100%" border="0" align="center"
cellpadding="0"
cellspacing="0" class="special">
(there is no table height attribute - it's invalid HTML)
> b, be too small, dependent upon which browser they are
viewed in.
Impossible. A background image will not change size in
different browsers.
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
==================
"chimesey" <[email protected]> wrote in
message
news:[email protected]...
>
quote:
Originally posted by:
Newsgroup User
> Use CSS -
>
> table { background-repeat:no-repeat; }
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
>
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
>
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
> ==================
>
> I am trying to do the same thing, and my bg images seem
to either
> a, repeat somewhat
> or
> b, be too small,
> dependent upon which browser they are viewed in.
>
> I will try to use the code suggested above, but where
exactly would I
> insert
> it?
> This is the code for the 'table within the table'...
>
> <table width="100%" height="606" border="0"
> align="center" cellpadding="0" cellspacing="0">
> <tr>
> <th width="35%" height="95"
> scope="col"><h1>ten</h1></th>
> <th width="26%"
scope="col"><h1>year</h1></th>
> <th width="39%"
scope="col"><h1>plan</h1></th>
> </tr>
> <tr>
> <td height="325"><table width="100%"
height="266"
> border="0" cellpadding="0" cellspacing="0">
> <tr>
> <th scope="col"> </th>
> <th background="../smiths.jpg"
> scope="col"> </th>
> <th scope="col"> </th>
> </tr>
> </table> <p> </p>
>
>
> Ta!
> -
I created a site with a table holding the background image.
Other tables are within this containing the content.
It works fine but if i use a .png image for the background i
get a thin blue line at the top. see here:
http://proof.outoffocusonline.com/
(it is visible above contact).
If i make the background image a .jpg or a .gif this problem
disappears - that is with making NO other changes just the name
extension.
Any ideas why this occurs? and how can i fix it? - the image
does not look nearly as good in gif form due to the shadow/glow
effect. And jpg boosts the filesize by a lot.
thanks.Does the PNG contain transparency?
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com
- Template Triage!
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
http://www.macromedia.com/support/search/
- Macromedia (MM) Technotes
==================
"John Waller" <[email protected]>
wrote in message
news:e3kn6e$opk$[email protected]..
> Somehow the background image
>
http://proof.outoffocusonline.com/images/bg.png
> has got a 1 pixel x 20 pixel (approx) blue fringe effect
added which is
> not the same color blue (#000099) as the rest of the
image.
>
> Has this been inadvertently added in your image editor?
>
> Can you post a link to a copy of the GIF version?
>
> --
> Regards
>
> John Waller
> -
Inserting table background image
I just upgraded from DW8 to CS4 and can't figure out how to
insert an image for a table background! The box and folder icon to
browse to the file I want is greyed out. Can anyone help?This is CS4's way of telling you that you have to use CSS for
such things.
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
==================
"tsheridan" <[email protected]> wrote in
message
news:gmb557$pu0$[email protected]..
>I just upgraded from DW8 to CS4 and can't figure out how
to insert an image
>for a table background! The box and folder icon to browse
to the file I
>want is greyed out. Can anyone help? -
Repeating background jpg image
I have my swf file embed into an html page and currenly have
the background set to #000000. I want to change this to a jpg image
that repeats for the entire background. I want the swf file to
appear with a transparent background so the repeating image shows
through.
I have searched forums, but nothing seems to work for me. The
jpg image will be name "back.jpg" and is going to be located in the
same folder as the swf and html files.
GreenMartianI finally found this tech note on making the flash movie with
a transparent background. If anyone needs this info.
Transparent
flash movie
Then, all I needed to do was set html background image to my
jpg file, and it worked fine. -
If I have a jpg with a white background around the actual image, is there any way to lose the white and just have the image?
Menu > Format > Instant Alpha > slide the cursor over the color you want to eliminate till it looks good
Peter -
How to print JPG image retrieved from BLOB in a table using Forms10g
I create a database schema and a Form to maintain JPG to the table PHOTOS.
I would like to add a button to PRINT just the PHOTO_IMAGE to its maximum size from a Form. How can I do that? Is thaere any built-in Forms functions to do that? If the client is using Windows XP, can I use CLIENT_HOST() to call a program to print the JPG file directly?
Any suggestion is welcome.
-- myphotos.sql
drop user myphoto cascade;
create user myphoto identified by myphoto;
grant connect, resource, ctxapp to myphoto;
connect myphoto/myphoto@orcl;
PROMPT Creating Table USERS
CREATE TABLE USERS
(USER_ID VARCHAR2(8) NOT NULL,
USER_LASTNAME VARCHAR2(15) NOT NULL,
USER_FIRSTNAME VARCHAR2(30) NOT NULL,
USER_PASSWORD VARCHAR2(20) NOT NULL,
CONSTRAINT PK_USERS PRIMARY KEY (USER_ID)
PROMPT Creating Table PHOTOS
CREATE TABLE PHOTOS
(PHOTO_ID VARCHAR2(15) NOT NULL,
PHOTO_IMAGE BLOB,
TEXT_DESCRIPTION CLOB,
FILENAME VARCHAR2(50),
FILE_SIZE NUMBER NOT NULL,
USER_ID VARCHAR2(8) NOT NULL,
ACCESS_RIGHT VARCHAR2(7) NOT NULL,
CONSTRAINT CK_ACCESS_RIGHT CHECK (ACCESS_RIGHT IN ('PRIVATE', 'PUBLIC')),
CONSTRAINT PK_PHOTOS PRIMARY KEY (PHOTO_ID),
CONSTRAINT FK_USER_ID FOREIGN KEY (USER_ID) REFERENCES USERS (USER_ID)
create index idx_photos_text_desc on
PHOTOS(TEXT_DESCRIPTION) indextype is ctxsys.context;
INSERT INTO USERS VALUES ('G345566A','WONG', 'TAI SIN','WONGTAISIN');
INSERT INTO PHOTOS VALUES
('P00000000000001', empty_blob(), empty_clob(),
'SCGP1.JPG',100,'G345566A','PUBLIC');
INSERT INTO PHOTOS VALUES
('P00000000000002', empty_blob(), 'Cold Play with me at the concert in Melbourne 2005',
'COLDPLAY1.JPG',200,'G345566A','PUBLIC');
INSERT INTO PHOTOS VALUES
('P00000000000003', empty_blob(), 'My parents in Melbourne 2001',
'COLDPLAY1.JPG',200,'G345566A','PRIVATE');
COMMIT;
EXEC CTX_DDL.SYNC_INDEX('idx_photos_text_desc');
SELECT USER_ID,PHOTO_ID ,TEXT_DESCRIPTION
FROM PHOTOS
ORDER BY USER_ID;
SELECT score(1),PHOTO_ID ,TEXT_DESCRIPTION
FROM PHOTOS
WHERE CONTAINS(TEXT_DESCRIPTION,'parents',1)> 0
ORDER BY USER_ID,score(1) DESC;
SELECT USER_ID,score(1),PHOTO_ID ,TEXT_DESCRIPTION
FROM PHOTOS
WHERE CONTAINS(TEXT_DESCRIPTION,'cold play',1)> 0
ORDER BY USER_ID,score(1) DESC;
SELECT USER_ID,score(1),score(2), PHOTO_ID ,TEXT_DESCRIPTION
FROM photos
WHERE ACCESS_RIGHT='PUBLIC'
AND CONTAINS(TEXT_DESCRIPTION,'Melbourne',1)> 0
AND CONTAINS(TEXT_DESCRIPTION,'2005',2)> 0
ORDER BY USER_ID,score(1) DESC;I use a third part product to do this (irfanview.exe).
This tool allows to do some batch operation /print to print the file)
Francois -
One pixel around borderless image in table
Hey,
I have an image in a table. I set the background color of the
table to a greyish blue, because the table is taller than the image
and i want there to be color below the image in the table. BUT ONLY
in the table. The width of the table is the same as the image. For
some reason, there is one pixel of the background color of the
table around the jpg, and I cant get it to go away. I tried
cellpadding="0", but that didn't do anything. I also tried negative
numbers, but taht didnt do anything either. Am I SOL or can I put
this image in the table without having the background exceed the
image?
Simple:
<table width="600" border="0" align="center">
<tr>
<td width="216"
background="../../Images/tablebgcolor.jpg"><p><img
src="../../Images/Old Main.jpg" alt="" width="216"
height="332"/></p>
</td>
<td width="374"> </td>
</tr>
</table>
Note that I used the image of the background color instead of
setting the background color itself. In either case it's the same,
and I can't get a different result. Thanks for the help,
--GWhat happens if you remove the <p> tag around the
image?
<p> tags have a default padding, so unless you zero
that out or move the
image of of the <p> you'll get some spacing around it.
Nadia
Adobe® Community Expert : Dreamweaver
CSS Templates |Tutorials |SEO Articles
http://www.DreamweaverResources.com
~ Customisation Service Available ~
http://www.csstemplates.com.au
Spry Widget Examples
http://www.dreamweaverresources.com/spry-widgets/
~ Forum Posting Guidelines ~
http://www.adobe.com/support/forums/guidelines.html
CSS Tutorials for Dreamweaver:
http://www.adobe.com/devnet/dreamweaver/css.html
"117236" <[email protected]> wrote in
message
news:gbkakt$8me$[email protected]..
> Hey,
> I have an image in a table. I set the background color
of the table to a
> greyish blue, because the table is taller than the image
and i want there
> to be
> color below the image in the table. BUT ONLY in the
table. The width of
> the
> table is the same as the image. For some reason, there
is one pixel of
> the
> background color of the table around the jpg, and I cant
get it to go
> away. I
> tried cellpadding="0", but that didn't do anything. I
also tried negative
> numbers, but taht didnt do anything either. Am I SOL or
can I put this
> image
> in the table without having the background exceed the
image?
>
> Simple:
>
> <table width="600" border="0" align="center">
> <tr>
> <td width="216"
background="../../Images/tablebgcolor.jpg"><p><img
> src="../../Images/Old Main.jpg" alt="" width="216"
height="332"/></p>
> </td>
> <td width="374"> </td>
> </tr>
> </table>
>
> Note that I used the image of the background color
instead of setting the
> background color itself. In either case it's the same,
and I can't get a
> different result. Thanks for the help,
> --G
> -
How to have a box layout on a JDialog, with an image set as background
Hi,
I need to have a JDialog in which there is a background image set (I already did this part, but only with the default layout). I further need to add text to the lower part of the JDialog. (For this, I guess I need to have a box layout.). I am not able to do so, because if I do so, I wont be able to set image background to the entire JDialog. Please help me out with how to solve this issue?
Thanks,
JobyHi jduprez,
Thanks for the reply. I checked Rob Camick's blog. It gives a nice way to add an image to a panel (*master panel*) and to use it.
I still have my problem open. The above solution gives panel that I can add to my JDialog. But on the bottom half of the image (as you said, BorderLayout.South), I need to add another structured set of components using a Border Layout again.!, ie, one more panel with a BorderLayout. So when I add
this panel, to the master panel containing the image, then the image gets cut off, at that point. I tried using component.setOpaque(false) on my sub-panel, still it does not work. Any idea, how to achieve this...?
Following is the code I have adapted.
public class BackgroundPanel extends JPanel
public static final int SCALED = 0;
public static final int TILED = 1;
public static final int ACTUAL = 2;
private Paint painter;
private Image image;
private int style = SCALED;
private float alignmentX = 0.5f;
private float alignmentY = 0.5f;
private boolean isTransparentAdd = true;
public static void main(String[] args) {
Image img = getImage("D:/imgs/Snowdrop.jpg");
BackgroundPanel panel = new BackgroundPanel(img);
JDialog dlg = new JDialog();
dlg.setLayout(new BorderLayout());
dlg.add(panel);
panel.setTransparentAdd(true);
Panel nPanel = new Panel();
nPanel.setLayout(new BorderLayout());
JLabel label = new JLabel();
//label.set
label.setText("<html>HI<br>This is another line<br><br><br><br><br><br><br><br><br><br></html>");
nPanel.add(label, BorderLayout.NORTH);
panel.add(nPanel/*label*/,BorderLayout.SOUTH);
dlg.setSize(600, 500);
dlg.setVisible(true);
private static Image getImage(String fileName){
File file = new File(fileName);
Image image = null;
try{
image = ImageIO.read(file);
catch(IOException ioe){
/*JOptionPane.showMessageDialog(dlg, "Error in loading image file",
"Error", JOptionPane.ERROR_MESSAGE, null);*/
return image;
* Set image as the background with the SCALED style
public BackgroundPanel(Image image)
this(image, SCALED);
* Set image as the background with the specified style
public BackgroundPanel(Image image, int style)
this(image,style,-1,-1);
* Set image as the backround with the specified style and alignment
public BackgroundPanel(Image image, int style, float alignmentX, float alignmentY)
setImage( image );
setStyle( style );
if (alignmentX > 0){
setImageAlignmentX( alignmentX );
if (alignmentY > 0){
setImageAlignmentY( alignmentY );
setLayout( new BorderLayout() );
* Use the Paint interface to paint a background
public BackgroundPanel(Paint painter)
setPaint( painter );
setLayout( new BorderLayout() );
* Set the image used as the background
public void setImage(Image image)
this.image = image;
repaint();
* Set the style used to paint the background image
public void setStyle(int style)
this.style = style;
repaint();
* Set the Paint object used to paint the background
public void setPaint(Paint painter)
this.painter = painter;
repaint();
* Specify the horizontal alignment of the image when using ACTUAL style
public void setImageAlignmentX(float alignmentX)
this.alignmentX = alignmentX > 1.0f ? 1.0f : alignmentX < 0.0f ? 0.0f : alignmentX;
repaint();
* Specify the horizontal alignment of the image when using ACTUAL style
public void setImageAlignmentY(float alignmentY)
this.alignmentY = alignmentY > 1.0f ? 1.0f : alignmentY < 0.0f ? 0.0f : alignmentY;
repaint();
* Override method so we can make the component transparent
public void add(JComponent component)
add(component, null);
* Override method so we can make the component transparent
public void add(JComponent component, Object constraints)
if (isTransparentAdd)
makeComponentTransparent(component);
super.add(component, constraints);
* Controls whether components added to this panel should automatically
* be made transparent. That is, setOpaque(false) will be invoked.
* The default is set to true.
public void setTransparentAdd(boolean isTransparentAdd)
this.isTransparentAdd = isTransparentAdd;
* Try to make the component transparent.
* For components that use renderers, like JTable, you will also need to
* change the renderer to be transparent. An easy way to do this it to
* set the background of the table to a Color using an alpha value of 0.
private void makeComponentTransparent(JComponent component)
component.setOpaque( false );
if (component instanceof JScrollPane)
JScrollPane scrollPane = (JScrollPane)component;
JViewport viewport = scrollPane.getViewport();
viewport.setOpaque( false );
Component c = viewport.getView();
if (c instanceof JComponent)
((JComponent)c).setOpaque( false );
* Add custom painting
protected void paintComponent(Graphics g)
super.paintComponent(g);
// Invoke the painter for the background
if (painter != null)
Dimension d = getSize();
Graphics2D g2 = (Graphics2D) g;
g2.setPaint(painter);
g2.fill( new Rectangle(0, 0, d.width, d.height) );
// Draw the image
if (image == null ) return;
switch (style)
case SCALED :
drawScaled(g);
break;
case TILED :
drawTiled(g);
break;
case ACTUAL :
drawActual(g);
break;
default:
drawScaled(g);
* Custom painting code for drawing a SCALED image as the background
private void drawScaled(Graphics g)
Dimension d = getSize();
g.drawImage(image, 0, 0, d.width, d.height, null);
* Custom painting code for drawing TILED images as the background
private void drawTiled(Graphics g)
Dimension d = getSize();
int width = image.getWidth( null );
int height = image.getHeight( null );
for (int x = 0; x < d.width; x += width)
for (int y = 0; y < d.height; y += height)
g.drawImage( image, x, y, null, null );
* Custom painting code for drawing the ACTUAL image as the background.
* The image is positioned in the panel based on the horizontal and
* vertical alignments specified.
private void drawActual(Graphics g)
Dimension d = getSize();
Insets insets = getInsets();
int width = d.width - insets.left - insets.right;
int height = d.height - insets.top - insets.left;
float x = (width - image.getWidth(null)) * alignmentX;
float y = (height - image.getHeight(null)) * alignmentY;
g.drawImage(image, (int)x + insets.left, (int)y + insets.top, this);
}Thanks,
Joby
Maybe you are looking for
-
Since the last update of evince to 0.83 it won't open pdf files no more - I get: Unable to open document Unhandled MIME type: "application/pdf" Is this a bug? I can open pdfs using kpdf or kghostview without a problem.
-
Making JButton not respond when hour glass cursor
Hi, I know how to change the cursor to the hour glass one but what I want is that JButtons will not responds to clicks from an hour glass cursor. The JButtons should only respond to clicks from the normal cursor. Does anyone know how to do this? Than
-
Hi, elementary question... in my program I have many labels as class variables. I initialize them all in init(). How can i change their font. All of them should be the same font, just not the default one. Also i would like to make certain ones bold.
-
Best method for saving settings
What is the generally accepted "best" way to store a programs settings? I was thinking of just using a text file as its easy to implement, is there any reason i shouldn't do this? Cheers J EDIT: Lets assume im not saving any sensitive data, just fluf
-
I'm getting an error message when I try to sync my iphone to my computer, "...unable to load data class information from sync services..." How do I fix this? I'm worried because my last computer was giving me this same error right before it crashed