Background not displaying in JPanel

I have tried virtually every method I can find on this site to display a jpg in a panel yet while it compiles fine the background does not show up. Can anybody please take a look at this code and try to figure out where I went wrong? Thank you
import java.awt.*;
import java.awt.event.*;
import java.awt.Image;
import javax.swing.*;
import javax.swing.filechooser.*;
import java.io.File;
import java.io.*;
public class Main implements ActionListener {
JFrame f1,login;
JLabel LID,LPW,LTitle;
JTextField TID,TPW;
JButton BLogin;
JPanel PTitle,IDPanel,PWPanel,LPanel,PL;
ImageIcon background;
public Main() {
CreateLogin();
login.setVisible(true);
public static void main(String[] args) {
new Main();
public void CreateLogin(){
login=new JFrame("Guelph-Humber Mark Program");
login.setSize(150,300);
Container LContainer = login.getContentPane();
LPanel=new JPanel(new BorderLayout());
LPanel.setOpaque(false);
//Adds title bar
PTitle=new JPanel(new FlowLayout());
PTitle.setOpaque(false);
LTitle=new JLabel("LOGIN");
PTitle.add(LTitle);
LPanel.add(PTitle,"North");
//Center Portion
background = new ImageIcon("bg.jpg");
PL=new JPanel(){
public void paintComponent(Graphics g) {//Overrides default JPanel paintcomponent method to draw the background
Dimension d = getSize();
g.drawImage(background.getImage(), 0, 0, d.width, d.height, null);
setOpaque(false);
super.paintComponent(g);
PL.setLayout(new GridLayout(2,1));
IDPanel=new JPanel();
IDPanel.setOpaque(false);
LID=new JLabel("ID:");
TID=new JTextField(12);
IDPanel.add(LID);
IDPanel.add(TID);
PWPanel=new JPanel();
PWPanel.setOpaque(false);
LPW=new JLabel("Password:");
TPW=new JTextField(12);
PWPanel.add(LPW);
PWPanel.add(TPW);
PL.add(IDPanel);
PL.add(PWPanel);
LPanel.add(PL,"Center");
//South portion
BLogin=new JButton("Login");
BLogin.addActionListener(this);
LPanel.add(BLogin,"South");
LContainer.add(LPanel);
//Window adapter to close program when frames closes
login.addWindowListener( new WindowAdapter() {public void windowClosing(WindowEvent evt) {System.exit(0);}});
public void actionPerformed(ActionEvent e) {
if(e.getSource()==BLogin){
}

1) Use the "code" tags when posting code so the posted code retains its original formatting.
2) Learn the Java Naming conventions. None of your variable names follow standards and its very confusing to read. Variable names should start with a lower case character (class names start with an upper case character)
3) The order of your code in the paintComponent(...) method is correct.
4) Your code works for me, so I'm guessing you are just not finding your image.

Similar Messages

  • Issue with correct slide background not displayed

    I am experiencing problems when publishing content captured from a simulation apart from the really annoying cursor ghosting when playing back typed text and the red screen of death and ghosting from previous slides when scrolling
    I am now getting a completely different background on the published and previewed through browser slide to the background the unpublished slide is designed to show I have of course checked the timeline for hidden overlays and have also dragged the background from the library over the existing background to see if that cured it but no it still shows a background that is present in the library but is nowhere on the slide
    the 2 slides either side play and look correct
    The slide is also displayed correctly when previewed using "from this slide" it is only when published or through browser that the problem occurs
    Strikes me that some of these issues are well past the time they should have been sorted I am begining to lose confidence in what should be a good tool but needs to be far more reliable
    what with giving hackers my credit card details Adobe seem to be sliding  and I am gueesing it is because they are getting greedy and quality is taking a back seat
    Everything is getting so buggy Acrobat Pro, Photoshop etc all getting very unreliable I work in a large training dept for a majopr co and I am seeing issues on all different machines and OS so it is not just my machine

    Hi Rod
    Thanks for your reply
    I have tried all the supposed fixes
    Inc changing quality of slides to 24 bit and no compression
    Maintain slide quality and not maintain slide quality, reducing size of file, export background to photoshop reimport jpg
    With mixed results, I would just like your product to do what it says it will
    The only way I have found to eradicate this problem and the others mentioned is to remove any fmr from the content
    I have checked for proxy cache republished in 3 versions of flash sometimes have got different results but all unacceptable
    I also note many others have had same problem without resolve
    Can you please halt development on new products until you resolve problems that have persisted across several versions
    I am also experiencing the close browser problem which I have solved by adding Javascript but surely you with your resources could do this for your
    Customers who pay very good money for your products
    I didn’t think I was buying a do it yourself kit
    Regards Chris Lord

  • JTable column is not displaying in JPanel

    I created a JTable with single column like
    New JTable(celldata, columndata);
    and added it into JPanel. In this case only table cells are displying but not the column. If I use JScrollPane, table column name does displyed.
    Any help would be appreciated.
    Thanks
    Satheesh

    That is the correct behaviour of the components. A table won't display the column headers unless it's in a JScrollPane. Though you can get the headers from the table yourself manually using getTableHeader and put them where you want.

  • Background not displaying properly in IE

    I am showing this design to a client at 10:30 this morning and checked it on IE.  Of course there is an issue!  ugh.  Can anyone tell me why my background is not repeating properly in IE?  Looks fine on my Mac in Firefox and Safari.  Any help would be greatly greatly appreciated.
    Here is the site in progress:
    http://www.twosistersdesign.com/echo/
    thanks-
    Dana

    I'm seeing the same as PZ, the page looks the same on PC IE 7 and FFox.  I don't see any 'blue' at the bottom of the page, looks like the gradient you are using for the background - albeit it it doesn't go right down to the whitish colour towards the bottom if the slice image.
    Nadia
    Adobe® Community Expert : Dreamweaver
    http://twitter.com/nadiap
    Unique CSS Templates |Tutorials |SEO Articles
    http://www.DreamweaverResources.com
    http://csstemplates.com.au/

  • Backgrounds not displaying at full width on ipad

    Hi, I am new to muse but Ive been working with a template I purchased and the backgrounds do not go full width when viewed on an ipad even though they are set to 100% width on my muse file. There is a white space on the right side.
    Website is: roundcorner.ca and mezzalunadesign.ca
    screen shots are below.

    Great, I revisited every page of the Muse file and found one that had some stray elements on the pasteboard to the right. I deleted these and hey presto, works perfectly on iPad now as well, background goes fully to the edges.
    Many thanks.

  • Osx mountain lion: reminders background not displayed correctly

    When I slide left and look at the reminders on the right, the background is black, but a bunch of squares overlapping each other. This is making the reminders very difficult to see, as it is under them too. How do I fix this?

    Try this...
    Go to your Finder "Go" menu hold the option key to choose "Library".
    Then, go to Containers/com.apple.reminders/Container.plist and delete that file then log out and back in or restart.
    Let us know...

  • Data not display in background layout

    Hi Expert,
    This is regarding screen layout.
    FBL3N report.... I have create new layout for report FBL3N. when i run the report in foeground all data display in proper layout.
    But when i run this report in Background two fields are not display in layout.
    Please suggest me whern i do the changes....
    Regards
    PK.

    I think you should change the forum if you are asking Finance module related qwuestions.

  • When I open a pdf in Adobe Acrobat xi pro it is not displaying correctly. If a file is all black with orange writing, I will see only the orange writing. Its not until i print it or open crop pages dialog box that i see the background. i am on a Windows 7

    When I open a pdf in Adobe Acrobat xi pro it is not displaying correctly. If a file is all black with orange writing, I will see only the orange writing. Its not until i print it or open crop pages dialog box that i see the background.
    i am on a Windows 7 professional PC, 64-bit.

    If anyone is reading this still looking for what caused the issue and how to fix it here is what I discovered.
    The antivirus program our company uses, Bitdefender Antivirus Plus, was causing some of the PDF files not to open. After troubleshooting the different modules and settings the culprit was..
    Scan SSL in Privacy Control Settings. Turning it OFF solved the problem and all the PDF files that previously would not open now open just fine. This issue has been sent to Bitdefender for them to review. If you use a different antivirus program and are having this issue try locating the Scan SSL setting and see if turning it off solves the problem.

  • Firefox will not display a complete page only framework w/o background. have reloaded 3X still junk.

    Full page with background does not display.

    Can you attach a screenshot?
    *http://en.wikipedia.org/wiki/Screenshot
    Use a compressed image type like PNG or JPG to save the screenshot and make sure that you do not exceed the maximum file size (1 MB).
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    If images are missing then check that you aren't blocking images from some domains.
    *You can inspect and manage all permissions on the about:permissions page, via the location bar.
    *Check the permissions for the domain in the current tab in "Tools > Page Info > Permissions"
    *Check that images are enabled: Tools > Options > Content: [X] Load images automatically
    *Check the exceptions in "Tools > Options > Content: Load Images > Exceptions"
    *Check the "Tools > Page Info > Media" tab for blocked images (scroll through all the images with the cursor Down key).
    If an image in the list is grayed and there is a check-mark in the box "<i>Block Images from...</i>" then remove that mark to unblock the images from that domain.
    Make sure that you do not block third-party images permissions.default.images
    *http://kb.mozillazine.org/Images_or_animations_do_not_load

  • Ibooks author, how do I get the standard book pages background into my document. I have published one book so far which does not display with a book pages background or options for font size.

    ibooks author, how do I get the standard book pages background into my document. I have published one book so far which does not display with a book pages background or options for font size.

    No on the book title, no problem there.
    The issue is: my book pages appear as on white paper, no background that resembles a open book and also no option to change fonts. The book was created in iBooks author, there was a problem going with the "Publish" menu route so I was instructed my Apple to "export" the file and submit that. I think that's the problem after reading that iBooks author is a hybrid epub file.
    Thanks for getting back to me.

  • Background-image of a Design Studio 1.3 extension is not displayed when the control is  dragged on the canvas

    Hello,
    I have a Design Studio Extension with a background image which behave well in Design Studio 1.2.
    In Design Studio 1.3 when I drag the control into the canvas the image does not show-up. If I execute the application the image appear in the browser even is not in the canvas.Once I save and reopen the application the image is displayed on the canvas as expected.
    I built an extension based on  the 'Timer' sample which comes with the DS_13_SDK_Samples ( it has a background image) and it behaves the same way - when you drag the control on the canvas, the image is not displayed.
    Any help to solve this issue is much appreciated.
    Thank you.

    It does start to work once I save and reopen or even when I run.
    I tried the inline style but the behavior is much stranger. It does work if I have a full address url to an image, but if my image is part of the control's folder structure it fails completely - it cannot map the right address to the image. The only configuration that appears to work better is the one with the original problem.
    Thank you.

  • Spry tab menu background image is not displaying on remote server

    Hello All,
    I have a problem with spry tab panel, it is not displaying image in the background when it is active, it is working properly in local server but when i upload to remote it vanishes.
    Here is the link
    http://www.geftas.com/temaritestpage/about.html
    Also I am uploading Css and html code below
    Any help would be exteremely appreciated.
    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=utf8"/>
    <meta http-equiv="content-type" content="cache" />
    <meta http-equiv="robots" content="INDEX,FOLLOW"  />
    <meta http-equiv="keywords" content="Enter Keywords"/>
    <meta http-equiv="description" content="Description Here" />
    <title>TEMARI&CO. | Business Strategists</title>
    <link href="css/about.css" rel="stylesheet" type="text/css" media="screen" />
    <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
    <script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
    <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
    <link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <div id="wrapper">
              <div id="header"></div>
      <div id="navigation">
        <ul id="MenuBar1" class="MenuBarHorizontal">
          <li><a href="index.html">HOME</a></li>
          <li><a href="about.html" class="current">ABOUT</a></li>
          <li><a href="#" class="MenuBarItemSubmenu">CONSULTING</a>
            <ul>
              <li><a href="#">Business Plan</a></li>
              <li><a href="#">Marketing Plan</a></li>
              <li><a href="#">Incorporation</a></li>
              <li><a href="#">Accounting System</a></li>
            </ul>
          </li>
          <li><a href="#" class="MenuBarItemSubmenu">INDUSTRIES</a>
            <ul>
              <li><a href="#">Untitled Item</a></li>
              <li><a href="#">Untitled Item</a></li>
              <li><a href="#">Untitled Item</a></li>
              <li><a href="#">Untitled Item</a></li>
            </ul>
          </li>
          <li><a href="#">OUR PROCESS</a></li>
          <li><a href="#">CAREERS</a>      </li>
          <li><a href="#">CONTACT</a></li>
        </ul>
      </div>
    <div class="shadow" id="content">
      <div id="TabbedPanels1" class="TabbedPanels">
        <ul class="TabbedPanelsTabGroup">
          <li class="TabbedPanelsTab" tabindex="0">values</li>
          <li class="TabbedPanelsTab" tabindex="0">people</li>
        </ul>
        <div class="TabbedPanelsContentGroup">
          <div class="TabbedPanelsContent">
                    <div id="scrolltext">
                        <h1>Heading1</h1>                 
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. N</p>
            </div>
          </div>
          <div class="TabbedPanelsContent">
                      <div id="scrolltext">
                        <h1>Heading1</h1>                 
            <p>Lorem n, </p>
                                <h1>Heading1</h1>                 
            <p>Lorem ipsum dolor sit amet, , </p>
                               <h1>Heading1</h1>                 
            <p>Lorem ipsum dolor sit a, </p>
                               <h1>Heading1</h1>                 
            <p>Lorem ipsum dolor sit amet,  </p>   
            </div>
          </div>
        </div>
      </div>
    </div>
      <div id="footer">
    <div id="legal">
                          <ul>
                              <li>Copyright © 2012 Temari&Co</li>
                        <li>| Privacy Policy |</li>
                        <li>Terms of Use</li>
                    </ul>
        </div>
                <div id="socialmedia">
                          <ul>
                              <li><img src="images/fbicongri.png" width="20" height="20" alt="fbicon" /></li>
                        <li><img src="images/gicongri.png" width="20"          height="20" alt="gicon"/></li>
                        <li><img src="images/linkedinicongri.png" width="20" height="20" alt="linkedin"/></li>
                        <li><img src="images/twittericongri.png" width="20" height="20" alt="twitter"/></li>
                  </ul>
          </div>   
      </div><!-- end footer-->   
    </div><!-- end wrapper-->
    <script type="text/javascript">
    var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
    var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
    </script>
    </body>
    </html>
    @charset "UTF-8";
    /* SpryTabbedPanels.css - version 0.6 - Spry Pre-Release 1.6.1 */
    /* Copyright (c) 2006. Adobe Systems Incorporated. All rights reserved. */
    /* Horizontal Tabbed Panels
    * The default style for a TabbedPanels widget places all tab buttons
    * (left aligned) above the content panel.
    .TabbedPanels {
              overflow: hidden;
              margin: 0px;
              padding: 0px;
              clear: none;
              width: 100%;
              height:100%; /* IE Hack to force proper layout when preceded by a paragraph. (hasLayout Bug)*/
    .TabbedPanelsTabGroup {
              margin: 0px;
              padding: 0px;
    .TabbedPanelsTab {
              position: relative;
              float: left;
              background-color: #FFF;
              list-style: none;
              -moz-user-select: none;
              -khtml-user-select: none;
              cursor: pointer;
              font-family: Arial, Helvetica, sans-serif;
              font-size: 9pt;
              font-weight: normal;
              color: #666;
              height: 30px;
              width: 116px;
              text-transform: uppercase;
              text-align: center;
              line-height: 30px;
              margin: 0px;
              padding: 0px;
    .TabbedPanelsTabHover {
              background-image: url(../../SUPEROLDU/images/menubaractive.png);
              background-repeat: repeat-x;
              color: #FFF;
    .TabbedPanelsTabSelected {
              background-image: url(../../SUPEROLDU/images/menubaractive.png);
              background-repeat: repeat-x;
              color: #FFF;
              height: 30px;
              width: 116px;
    .TabbedPanelsTab a {
              color: black;
              text-decoration: none;
    .TabbedPanelsContentGroup {
              clear: both;
              background-color: #FFF;
              height: 100%;
              width: 824px;
              font-family: Arial, Helvetica, sans-serif;
              font-size: 9pt;
              color: #666;
              border-top-width: 1px;
              border-right-width: 1px;
              border-bottom-width: 1px;
              border-left-width: 1px;
              border-top-style: dotted;
              border-top-color: #CCC;
              border-right-color: #CCC;
              border-bottom-color: #CCC;
              border-left-color: #CCC;
    .TabbedPanelsContent {
              height: 100%;
              width: 100%;
              overflow:hidden;
    .TabbedPanelsContentVisible {
    .VTabbedPanels {
              overflow: hidden;
              zoom: 1;
    .VTabbedPanels .TabbedPanelsTabGroup {
              float: left;
              background-color: #EEE;
              position: relative;
    .VTabbedPanels .TabbedPanelsTab {
              float: none;
              margin: 0px;
              border-top: none;
              border-left: none;
              border-right: none;
    .VTabbedPanels .TabbedPanelsTabSelected {
              background-color: #EEE;
    .VTabbedPanels .TabbedPanelsContentGroup {
              clear: none;
    /* Styles for Printing */
    @media print {
    .TabbedPanels {
              overflow: visible !important;
    .TabbedPanelsContentGroup {
              display: block !important;
              overflow: visible !important;
              height: auto !important;
              margin-top: 0px;
              margin-right: auto;
              margin-bottom: 0px;
              margin-left: auto;
    .TabbedPanelsContent {
              clear:both !important;
              margin-top: 0px;
              margin-right: auto;
              margin-bottom: 0px;
              margin-left: auto;
              width: 744px;
    .TabbedPanelsTab {
               overflow: visible !important;
               display: block !important;
               clear:both !important;

    Assuming these are the images you're trying to display:
    .TabbedPanelsTabHover {
              background-image: url(../../SUPEROLDU/images/menubaractive.png);
              background-repeat: repeat-x;
              color: #FFF;
    .TabbedPanelsTabSelected {
              background-image: url(../../SUPEROLDU/images/menubaractive.png);
              background-repeat: repeat-x;
              color: #FFF;
              height: 30px;
              width: 116px;
    You have 2 root paths in your URL code. I think this is how your file structure looks like on your local computer. However, on a remote server, ../ by itself means you're pointing to the root folder of your website. Your URL linkage should be corrected based on the relativity and your background will work without a problem.

  • CFGrid tag not displaying background color

    Hi, My application runs on CF v 4.5 and uses CFGrid tag to
    display grids. When I run the same code on MX 7, the grid does not
    display the pale yellow background for the grid as it does on 4.5.
    Does anyone know how to fix this ?
    Thanks, Jay M.

    Hi CatJay
    I looked at the code you sent and it has no attribute in
    place to display any color in the background, so I am guessing that
    maybe back in 4.5 there was only 1 colour by default?
    Try adding bgcolor="#ffff00" to the cfgrid tag and see if
    that changes the colour to yellow. (it should)
    Once you get that to work, you can implement any colour you
    want.

  • SSRS Report - background image not displaying in MHTML email

    We have a report that has a rectangle with an image as a background (doesn't make any difference whether image is external, embedded, etc). The background image displays fine on the screen and when exporting to PDF, but doesn't show when emailing (via subscription)
    in MHTML format and opening in MS Outlook, gmail, etc.
    It seems to be a legitimate bug with SSRS (have tried in SSRS 2008 R2, 2012, 2014).
    Is there a workaround? Service Pack?

    Hi Corey Gray,
    Per my understanding that the background image in the email subscription not display which format is MHTML, right?
    I have tested on my local environment and can reproduce the issue. I deliver this report to three email amounts: Outlook, Hotmail and 163, below I will share the test results with you.
    Outlook: the backgroudimage disappear in the email body and there is no one attachment being sent in the email.
    Hotmail: the backgroudimage disappear in the email body, however, the backgroundimage being sent as one attachment in the email.
    163: the backgroudimage displays in the email body and the backgroundimage being sent as one attachment in the email.
    Based on previous test results, we can conclude that: these different scenarios caused by the settings of the email rather than Reporting Services.
    If you are using Outlook, I would recommend you submit one thread in this Outlook forum,
    http://social.technet.microsoft.com/Forums/en-us/outlook/threads.
    In this forum, you can get more professional support about how to set the Outlook.
    If you have any other question, please feel free to let me know.
    Regards
    Vicky Liu

  • Background image not displaying properly

    My site is not displaying correctly on mobiles and ipads.  I want my background image to span the width of most widescreen monitors but it's not displaying correctly.  I am sure I am doing something wrong.  Also have some problems with the map not spanning the width on some devices.  Any help greatly appreciated.
    Website:  cdic.us
    Thanks in advanced.

    Does it help if you change this:
    html, body {
        margin: 0;
        padding: 0;
        background-color: #F0F0E3;
        background-repeat: no-repeat;
    to this:
    html, body {
        margin: 0;
        padding: 0;
        background-color: #F0F0E3;
        background-repeat: repeat-y;
    Martin

Maybe you are looking for

  • ITunes 10.5 64 bit version won't install on Windows 7 PC

    After 5 hours, I still cannot download the 64 bit version of iTunes 10.5 on my Windows 7 computer.  Removed all anti-virus protection, uninstalled and reinstalled, rebooted, etc.  Nothing.  Seems to be a big problem.  Any thoughts?  Thanks.

  • PS and LR CC, neither app will launch...

    Just bought and installed PS and LR via CC both apps installed and are in the correct win dir. Neither app will launch (tho PS does very quickly flash the splash screen before closing). I have tried the fix at http://helpx.adobe.com/photoshop/kb/cc-a

  • Mouse pointer is erratic.

    Hi folks. I have a problem in Logic where the mouse pointer doesn't always show the correct icon for the underlying control, this can make simple tasks like selecting volume nodes, or mini notes difficult. It's not a show stopper but I wonder if ther

  • Sites defeat open in new tab

    Some sites are defeating [Ctrl]-click to open in New Tab (my Firefox setting). In these sites [Ctrl]-click causes the original page to open. I have to use the [Right-Click] Context Menu, [Open Link in New Tab] option. Here's an example site: http://w

  • UNABLE TO USE  COMPILED CLASSES STORED IN DIFFERENT FOLDERS

    Can you help me out i have a problem i have been creating various modules and the compiled classes files are stored in different folders and i want the module to access the compiles classes file from the respective folders can any one give me some id