Trouble with background image in JPanel

I'm trying to get an image to display as a background image, and then put JLabels with other content on top of that background image. I've tried several things but can't figure out how to do it. Everytime I try, I get the images to display but the content is displayed side by side because of the layout manager.
I've tried this but the image is displayed very tiny and still is not displayed in the background.
   //*   Draw background images for panels            *
       public class BackgroundPanel extends JPanel
      // the image you want displayed in the background
         private Image background;
      // A constructor to build and initialise your panel.
      // @param resourceName
          public BackgroundPanel(String resourceName)
            background = new ImageIcon( getClass().getClassLoader().getResource( resourceName )).getImage();
            setOpaque(false);
      // @see java.awt.Container#paint(java.awt.Graphics)
          public void paint(Graphics g)
            g.drawImage(background, 0, 0, 200, 480, this);          
         // draw the rest of the panel and it's children
              super.paint(g);
      }

To add a background to a Swing component, do not overload the public void paint(Graphics g); methods, but the public void paintComponent(Graphics g); instead, otherwise, the background will always overlap the Swing components added.
Here is a goog working code:
public void paintComponent(Graphics g) {
     super.paintComponent(g);
     g.drawImage(myStaticBackground, this.getWidth() - 256, this.getHeight() - 256, this);
}In this example, I draw a static Image sized 256�256 at the bottom right corner.
Fabruccio
Java J2SE 1.5

Similar Messages

  • Background Image in JPanel.

    Hi, I am trying to set a background image to my JPanel. So far everything ok. However When I add labels to this panel as well the image is displayed but the label is not! I tried to make a search on google, and I found some links pointing to this forum, however none of them (which) I have seen show how to display a backgroun image and a label on top.
    What I tried to to is override the paint method of the JPanel. Here I did the following code:
    public void paint(Graphics g){
       Image i = this.myImage // Were myImage is of type Image with a loaded image in.
       g = super.getGraphics();
       g.drawImage(i, 0, 0, this);
       super.paint(g);
    }However this code brings the label and the image always blinking. I can imagine the reason for this is that the paint method is called all the time, and thus the image and the label are being painted all the time and so there is the blinking effect.
    Does anyone know how I can set a background image to my JPanel in an efficient way?

    No Gosling? I just retried it and it works for me.
    Maybe you're having trouble with the image URL.
    Try it with a local image.

  • FF36: Sites with background image flickers/flashes when going back to tab after 2 minutes.

    Figure I'll mention this here as well.
    When viewing websites with background images, such as twitter.com or my own website at www.markheadrick.com and I change to another tab for 2 minutes (this amount of time is repeatable anyway) I get a flicker of a black background before the page is fully drawn. If I have multiple tabs with the same background image, only the first tab will show the flicker. It's like it's loosing the image in memory or something. It has done this with Firefox in Safe Mode and with a new, clean profile. It has also done this with Hardware Acceleration off.
    Windows 7 Pro 64bit w/ NVidia 550ti and 314.22 drivers. Newer drivers are more problematic which is why I have stayed with these.
    Again, only pages with background images seem to show this flicker. Did not happen with Firefox 35 on my system.
    I created a bug for it here: https://bugzilla.mozilla.org/show_bug.cgi?id=1137082
    Thanks,
    Mark H

    I tried, but could not see and problem.
    Hello,
    In order to better assist you with your issue please provide us with a screenshot. If you need help to create a screenshot, please see [[How do I create a screenshot of my problem?]]
    Once you've done this, attach the saved screenshot file to your forum post by clicking the '''Browse...''' button below the ''Post your reply'' box. This will help us to visualize the problem.
    Thank you!

  • Background image  for JPanel using UI Properties

    Is there any way to add background image for JPanel using UI Properties,
    code is
    if (property.equals("img")) {
    System.out.println("call image file in css"+comp);
    //set the background color for Jpanel
    comp.setBackground(Color.decode("#db7093"));
    here the comp is JPanel and we are setting the background color,
    Is there any way to put the Background image for the JPanel ????

    KrishnaveniB wrote:
    Is there any way to put the Background image for the JPanel ????Override the paintComponent(...) method of JPanel.
    e.g.
    import javax.swing.*;
    import java.awt.*;
    import java.io.*;
    import javax.imageio.ImageIO;
    public class ImagePanel {
        public void createAndShowUI() {
            try {
                JFrame frame = new JFrame("Background Image Demo");
                final Image image = ImageIO.read(new File("/home/oje/Desktop/icons/yannix.gif"));
                JPanel panel = new JPanel() {
                    protected void paintComponent(Graphics g) {
                        g.drawImage(image, 0, 0, null);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setSize(new Dimension(400, 400));
                frame.setContentPane(panel);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            } catch (IOException ex) {
                ex.printStackTrace();
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new ImagePanel().createAndShowUI();
    }

  • Looking to create fully editable PDF files with background images

    Hello and thank you, I create menu's and flyers for a group of restaurants. I need to make text editable PDF menus with background images. I believe Livecycle is able to do this, but would really like to hear it from someone who knows for sure. Again thank you.
    Cheers,
    Charlie

    Yes it can. Download a free trial and try it out.

  • Trouble with opening images from dreamweaver cs6(64bit) to photoshop cs6(64bit).

    Hi guys i need help! I have trouble with opening images from dreamweaver cs6(64bit) to photoshop cs6(64bit). I uninstalled and went to preferences/file types editors to set up ps6 as primary but I still get some error.After i click image in dreamweaver,I get this message-Unable to launch...Please be sure that application exists and that there is enough memory to run it..

    Can you Launch Photoshop normally from your desktop shortcuts?
    I usually keep DW and PS open at all times so I can switch back & forth.
    Nancy O.

  • Problem with Background image and JFrame

    Hi there!
    I've the following problem:
    I created a JFrame with an integrated JPanel. In this JFrame I display a background image. Therefore I've used my own contentPane:
    public class MContentPane extends JComponent{
    private Image backgroundImage = null;
    public MContentPane() {
    super();
    * Returns the background image
    * @return Background image
    public Image getBackgroundImage() {
    return backgroundImage;
    * Sets the background image
    * @param backgroundImage Background image
    public void setBackgroundImage(Image backgroundImage) {
    this.backgroundImage = backgroundImage;
    * Overrides the painting to display a background image
    protected void paintComponent(Graphics g) {
    if (isOpaque()) {
    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());
    if (backgroundImage != null) {
    g.drawImage(backgroundImage,0,0,this);
    super.paintComponent(g);
    Now the background image displays correct. But as soon as I click on some combobox that is placed within the integrated JPanel I see fractals of the opened combobox on the background. When I minimize
    the Frame they disappear. Sometimes though I get also some fractals when resizing the JFrame.
    It seems there is some problem with the redrawing of the background e.g. it doesn't get redrawn as often as it should be!?
    Could anyone give me some hint, on how to achieve a clear background after clicking some combobox?
    Thx in advance

    I still prefer using a border to draw a background image:
    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;
    }And here is a demo where I load the background image asynchronously, so that I can launch the GUI before the image is done loading. Warning: you may find the image disturbing...
    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://today.java.net/jag/bio/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);
    }

  • Trouble with "body" images lining up at the top

    Hi, I am having troubles with the #body style in my web page. I have inserted a table into the #body area and the the body editable region will not line up on the top with the sideBar editable region when I add text and apply my css to it. Can you look at the code and let me know what I am doing wrong? 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=utf-8" />
    <!-- TemplateBeginEditable name="doctitle" -->
    <title>Ram Restaurant &amp; Brewery</title>
    <!-- TemplateEndEditable -->
    <meta name="keywords" content="Ram Restaurant, The Ram restaurant, Ram Restaurant and brewpub, Ram Restaurant Group, Ram International" />
    <meta name="description" content="Welcome to The Ram!  Your stomach wants food.  Your tastebuds want beer.  Satisfy them both at the Ram Restaurant & Brewery." />
    <style type="text/css">
    <!--
    body {
    background-color: #333;
    margin: 0 auto;
    padding: 0px;
    margin-left: 0px;
    margin-right: 0px;
    .navbar_center {
    text-align: center;
    -->
    </style>
    <link href="/RamWebsite_NEW/cssstyles.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    <!--
    body,td,th {
    font-family: Arial, Helvetica, sans-serif;
    color: #F00;
    margin: 0px;
    padding: 0px;
    a:link {
    color: #666;
    text-decoration: none;
    h1 {
    font-size: 36px;
    color: #000;
    h2 {
    font-size: 24px;
    color: #000;
    h3 {
    font-size: 18px;
    color: #000;
    h4 {
    font-size: 12px;
    color: #000;
    a:visited {
    text-decoration: none;
    color: #000;
    a:hover {
    text-decoration: underline;
    a:active {
    text-decoration: none;
    -->
    </style>
    <!--[if lte IE 8]>
    <style type="text/css">
    ul.MenuBarHorizontalul  li ul li ul li.MenuBarHorizontal, ul.MenuBarHorizontal li ul li.MenuBarHorizontal {
    width:100px;
    height:23px;
    </style>
    <![endif]-->
    <script src="/RamWebsite_NEW/SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
    <script type="text/javascript">
    <!--
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    //-->
    </script>
    <link href="/RamWebsite_NEW/SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
    <!-- TemplateBeginEditable name="head" -->
    <!-- TemplateEndEditable -->
    </head>
    <body link="#000000" topmargin="0" onload="MM_preloadImages('/RamWebsite_NEW/images/Menu_rollover.jpg','/RamWebsite_NEW/imag es/EventsLink2_rollover.jpg','/RamWebsite_NEW/images/GiftCards_rollover.jpg','/RamWebsite_ NEW/images/BeerLink2_rollover.jpg')">
    <div id="wrapper">
    <div id="header">
        <table width="900" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <th width="200" height="36" rowspan="2" align="center" valign="middle" scope="col"><a href="http://www.theram.com"><img src="/RamWebsite_NEW/images/Ram-Logo-red.gif" alt="Ram Restaurant &amp; Brewery Logo" width="175" height="69" border="0" /></a></th>
            <th width="350" height="50" align="center" valign="middle" scope="col"> </th>
            <th width="200" align="center" valign="middle" scope="col"> </th>
            <th width="150" align="right" valign="middle" scope="col"><a href="http://www.facebook.com/home.php?#!/theramrestaurant?ref=ts"><img src="/RamWebsite_NEW/images/FacebookBox.gif" alt="Becoma a Facebook Fan!" width="40" height="40" border="0" /></a><a href="http://www.twitter.com/theram"><img src="/RamWebsite_NEW/images/TwitterBox.gif" alt="Follow Us on Twitter" width="40" height="40" hspace="30" border="0" /></a></th>
          </tr>
          <tr>
            <th colspan="3" align="right" scope="col"><ul id="MenuBar1" class="MenuBarHorizontal">
              <li><a class="MenuBarItemSubmenu" href="#">MENU</a>
                <ul>
                  <li><a href="#" class="MenuBarItemSubmenu">Idaho</a>
                    <ul>
                      <li><a href="/menus/idaho/boise.shtml">Boise</a></li>
                      <li><a href="/menus/idaho/meridian.shtml">Meridian</a></li>
                    </ul>
                  </li>
                  <li><a href="#" class="MenuBarItemSubmenu">Illinois</a>
                    <ul>
                      <li><a href="/menus/illinois/rosemont.shtml">Rosemont</a></li>
                      <li><a href="/menus/illinois/schaumburg.shtml">Schaumburg</a></li>
                      <li><a href="/menus/illinois/wheeling.shtml">Wheeling</a></li>
                    </ul>
                  </li>
                  <li><a href="#" class="MenuBarItemSubmenu">Indiana</a>
                    <ul>
                      <li><a href="/menus/indiana/fishers.shtml">Fishers</a></li>
                      <li><a href="/menus/indiana/indianapolis.shtml">Indianapolis</a></li>
    </ul>
                  </li>
                  <li><a href="#" class="MenuBarItemSubmenu">Oregon</a>
                    <ul>
                      <li><a href="/menus/oregon/clackamas.shtml">Clackamas</a></li>
                      <li><a href="/menus/oregon/salem.shtml">Salem</a></li>
                    </ul>
                  </li>
                  <li><a href="#" class="MenuBarItemSubmenu">Washington</a>
                    <ul>
                      <li><a href="/menus/washington/kent.shtml">Kent</a></li>
                      <li><a href="/menus/washington/lacey.shtml">Lacey</a></li>
                      <li><a href="/menus/washington/lakewood.shtml">Lakewood</a></li>
                      <li><a href="/menus/washington/puyallup.shtml">Puyallup South Hill Mall</a></li>
                      <li><a href="/menus/washington/puyallup2.shtml">Puyallup Sunrise Village</a></li>
                      <li><a href="/menus/washington/northgate.shtml">Seattle Northgate</a></li>
                      <li><a href="/menus/washington/seattle.shtml">Seattle University Village</a></li>
                      <li><a href="/menus/washington/tacoma.shtml">Tacoma</a></li>
                    </ul>
                  </li>
                </ul>
              </li>
              <li><a href="#" class="MenuBarItemSubmenu">LOCATIONS</a>
                <ul>
                  <li><a href="#" class="MenuBarItemSubmenu">Idaho</a>
                    <ul>
                      <li><a href="/idaho/boiseNew.html">Boise</a></li>
                      <li><a href="/idaho/meridianNew.html">Meridian</a></li>
                    </ul>
                  </li>
                  <li><a href="#" class="MenuBarItemSubmenu">Illinois</a>
                    <ul>
                      <li><a href="/illinois/rosemontNew.html">Rosemont</a></li>
                      <li><a href="/illinois/schaumburgNew.html">Schaumburg</a></li>
                      <li><a href="/illinois/wheelingNew.html">Wheeling</a></li>
                    </ul>
                  </li>
                  <li><a href="#" class="MenuBarItemSubmenu">Indiana</a>
                    <ul>
                      <li><a href="/indiana/fishersNew.html">Fishers</a></li>
                      <li><a href="/indiana/indianapolisNew.html">Indianapolis</a></li>
                    </ul>
                  </li>
                  <li><a href="#" class="MenuBarItemSubmenu">Oregon</a>
                    <ul>
                      <li><a href="/oregon/clackamasNew.html">Clackamas</a></li>
                      <li><a href="/oregon/salemNew.html">Salem</a></li>
                    </ul>
                  </li>
                  <li><a href="#" class="MenuBarItemSubmenu">Washington</a>
                    <ul>
                      <li><a href="/washington/kentNew.html">Kent</a></li>
                      <li><a href="/washington/laceyNew.html">Lacey</a></li>
                      <li><a href="/washington/lakewoodNew.html">Lakewood</a></li>
                      <li><a href="/washington/puyallup-southHill-NEW.html">Puyallup South Hill Mall</a></li>
                      <li><a href="/washington/puyallup-Sunrise-New.html">Puyallup Sunrise Village</a></li>
                      <li><a href="/washington/northgateNew.html">Seattle Northgate</a></li>
                      <li><a href="/washington/seattleNew.html">Seattle University Village</a></li>
                      <li><a href="/washington/tacomaNew.html">Tacoma</a></li>
                    </ul>
                  </li>
                </ul>
              </li>
              <li><a class="MenuBarItemSubmenu" href="#">PROMOS</a>
                <ul>
                  <li><a href="/drink_specials.shtml">Drink Promos</a>              </li>
                  <li><a href="/food_specials.shtml">Food Promos</a></li>
    </ul>
              </li>
              <li><a href="/news.shtml">RAM NEWS</a></li>
              <li><a href="/about.shtml">ABOUT US</a></li>
              <li><a href="#" class="MenuBarItemSubmenu">CONTACT US</a>
                <ul>
                  <li><a href="/contact.shtml">General Info</a></li>
                  <li><a href="/employment.shtml">Careers</a></li>
                  <li><a href="/comments.shtml">Comments</a></li>
                </ul>
              </li>
              <li><a href="/banquets.shtml" class="MenuBarItemSubmenu">BANQUETS</a>
                <ul>
                  <li><a href="/banquets.shtml">Banquets</a></li>
                  <li><a href="/banquets-catering.shtml">Off-Site Catering</a></li>
                </ul>
              </li>
            </ul></th>
          </tr>
          <tr>
            <th colspan="4" align="center" valign="middle" scope="col"><img src="/RamWebsite_NEW/images/redbar.gif" width="900" height="11" /></th>
          </tr>
        </table>
    </div>
    <div id="body">
      <table width="900" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <th height="300" valign="top" scope="col"><table width="900" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <th width="225" align="center" valign="top" bgcolor="#000000" scope="col"><!-- TemplateBeginEditable name="sideBar" -->adfadsfds<!-- TemplateEndEditable --></th>
              <th width="675" align="left" valign="top" bgcolor="#FFFFFF" scope="col"><!-- TemplateBeginEditable name="body" -->
                <p><img src="/images/aboutus2.jpg" width="675" height="300" /></p>
                <p class="foodNameDesc">adfadslkj</p>
              <!-- TemplateEndEditable --></th>
            </tr>
          </table></th>
        </tr>
      </table>
    </div>
    <div id="bottomMenuSubPg">
      <table width="900" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <th width="200" align="center" scope="col"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Menu','','/RamWebsite_NEW/images/Menu_rollover.jpg',1)"><img src="/RamWebsite_NEW/images/Menu.jpg" alt="Menu" name="Menu" width="212" height="125" hspace="6" border="0" id="Menu" /></a></th>
          <th width="200" align="center" scope="col"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Big Horn Beer','','/RamWebsite_NEW/images/BeerLink2_rollover.jpg',1)"><img src="/RamWebsite_NEW/images/BeerLink2.jpg" alt="Big Horn Beer" name="Big Horn Beer" width="212" height="125" hspace="6" border="0" id="Big Horn Beer" /></a></th>
          <th width="200" align="center" scope="col"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Events','','/RamWebsite_NEW/images/EventsLink2_rollover.jpg',1 )"><img src="/RamWebsite_NEW/images/EventsLink2.jpg" alt="Events at the Ram" name="Events" width="212" height="125" hspace="6" border="0" id="Events" /></a></th>
          <th width="200" align="center" scope="col"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Gift Cards','','/RamWebsite_NEW/images/GiftCards_rollover.jpg',1)"><img src="/RamWebsite_NEW/images/GiftCards.jpg" alt="Gift Cards" name="Gift Cards" width="212" height="125" hspace="6" border="0" id="Gift Cards" /></a></th>
        </tr>
      </table>
    </div>
    <div id="bottommenu2"></div>
    <map name="Map" id="Map">
      <area shape="poly" coords="16,103" href="#" />
      <area shape="poly" coords="49,71,102,58,158,73,191,113,180,141,151,161,109,169,65,162,31,141,18,112" href="http://theram.fbmta.com/members/UpdateProfile.aspx?Action=Subscribe&amp;InputSource=W" target="_blank" />
    </map>
    <script type="text/javascript">
    <!--
    var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"/RamWebsite_NEW/SpryAssets/SpryMenuBarDownHover.gif", imgRight:"/RamWebsite_NEW/SpryAssets/SpryMenuBarRightHover.gif"});
    //-->
    </script>
    </div>
    </body>
    </html>

    You have your image in the 'body editable region' wrapped in <p></p> tags (paragraph tags). <p> tags have padding and margin set on them by default.
    <p><img src="/images/aboutus2.jpg" width="675" height="300" /></p>
    You can either just remove the <p></p> tags or you can zero out the padding and margin:
    p {
    padding: 0;
    margin: 0;
    Unfortuanately the above will target every paragraph on your page which might not be desirable so I would just remove the <p> tags as it is not necessary to wrap an image in them.
    If you do want to keep the <p> tags then use some inline css to specifically remove the padding and margin on that particular one:
    <p style="padding: 0; margin: 0;"><img src="/images/aboutus2.jpg" width="675" height="300" /></p>

  • Background image for JPanel

    I was to come here and "search" for examples on this but i havnt found any so im jsut going to post it:
    How do i set an image to be the background of a JPanel? setBackground(image); doesnt work... i was toal something about paintComponent() but i tried it with that too and it didnt work... anyhelp would be greatly appreciated

    Ive tried many of the things that search suggested but none of them pertained enough to what i am doing for it to work. Here is my code:package gameFunctions;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    public class loginScreen extends JFrame implements ActionListener
         JTextField USERNAME, Username, PASSWORD, Password; // yeah i know, bad practice but there is some logic to the names relative to capitalization
         String username, password;
         JButton LOGIN;
         Dimension res = Toolkit.getDefaultToolkit().getScreenSize();
         ImageIcon background = new ImageIcon("C:\\FileTesting\\testImage.jpg");;
         JPanel pane;
    public static void main(String[] args)
              loginScreen frame = new loginScreen();
              frame.setVisible(true);
    public loginScreen()
              Container c = getContentPane();
              setSize(400, 300);
              setLocation((int)res.getWidth()/2-getWidth()/2, (int)res.getHeight()/2-getHeight()/2);
              setResizable(false);
              setLayout(null);
              pane = new JPanel();
              pane.setSize(getWidth(), getHeight());
              pane.setLayout(null);
              c.add(pane);
              USERNAME = new JTextField("Username:");
              USERNAME.setSize(68,25);
              USERNAME.setLocation(getWidth()/2-USERNAME.getWidth()/2-80, getHeight()/2-USERNAME.getHeight()/2-50);
              USERNAME.setEditable(false);
              pane.add(USERNAME);
              PASSWORD = new JTextField("Password:");
              PASSWORD.setSize(68,25);
              PASSWORD.setLocation(USERNAME.getX(), USERNAME.getY()+30);
              PASSWORD.setEditable(false);
              pane.add(PASSWORD);
              Username = new JTextField();
              Username.setSize(150,25);
              Username.setLocation(USERNAME.getX()+USERNAME.getWidth()+5, USERNAME.getY());
              Username.setEditable(true);
              pane.add(Username);
              Password = new JTextField();
              Password.setSize(150,25);
              Password.setLocation(Username.getX(), Username.getY()+30);
              Password.setEditable(false); // because im not working with PW's yet
              pane.add(Password);
              LOGIN = new JButton("LOGIN");
              LOGIN.setSize(80,30);
              LOGIN.setLocation(getWidth()/2-LOGIN.getWidth()/2, PASSWORD.getY()+30);
              pane.add(LOGIN);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
    public void actionPerformed(ActionEvent event)
    }i want "pane" to be the image of "background" imageIcon is the only thing that works like this because i dont know how to use straight up "Image". everything works if i set the ImageIcon "background" to be the background of JButton "LOGIN"
    any help would be greatly appreciated

  • Having trouble making background image editable in template

    Hello this is my first time so here goes...
    I would like to make a template from a page I have created,
    the trouble is the background image is url background image placed
    in css with text over the image, the problem I have is on further
    pages I would like to keep same divs
    but would like the freedom to change text and bground image.
    I have tried to make text an editable region which works and
    bground image make attribute editable but I do not really
    understand how this works any ideas would be much appreciated here
    is my site address
    http://www.andysite.prohost4u.co.uk
    cheers

    I'm confused, I dont see that you have a background image in
    your css.
    "WILLO THE WISP" <[email protected]> wrote
    in message
    news:[email protected]...
    >
    Hello this is my first time so here goes...
    > I would like to make a template from a page I have
    created, the trouble is
    > the
    > background image is url background image placed in css
    with text over the
    > image, the problem I have is on further pages I would
    like to keep same
    > divs
    > but would like the freedom to change text and bground
    image. I have tried
    > to
    > make text an editable region which works and bground
    image make attribute
    > editable but I do not really understand how this works
    any ideas would be
    > much
    > appreciated here is my site address
    http://www.andysite.prohost4u.co.uk
    > cheers
    >
    >
    > Here is my css
    > * {
    > margin : 0 auto;
    > padding : 0;
    > }
    > body {
    > background-color : #ffffff;
    > text-align : center;
    > font-family : "Square721 BT", "Staccato222 BT", Courier;
    > font-size : 100%;
    > background-position : center center;
    > }
    > #container {
    > font-family : "Square721 BT", "Staccato222 BT", Courier;
    > background-color : #ffffff;
    > width : 780px;
    > }
    > #header {
    > width : 780px;
    > height : 280px;
    > margin-top : 10px;
    > margin-bottom : 10px;
    > }
    > #content {
    > background-image: url(images/content_bground.gif);
    > float: left;
    > height: 400px;
    > width: 430px;
    > }
    > #content h1 {
    > font-size : 115%;
    > width : 390px;
    > color : #00ccff;
    > text-align : left;
    > padding-left : 60px;
    > padding-top : 40px;
    > padding-bottom : 10px;
    > }
    > #content p {
    > font-size : 80%;
    > width : 310px;
    > text-align : justify;
    > text-indent : 20px;
    > color : #66FFFF;
    > }
    > #content h2 {
    > font-size : 80%;
    > width : 420px;
    > color : #00ccff;
    > text-align : left;
    > padding-left : 60px;
    > height : 70px;
    > padding-top : 10px;
    > }
    > #sidebar {
    > background-image : url(images/sidebar_bground.gif);
    > width : 340px;
    > height : 400px;
    > float : right;
    > }
    > #sidebar ul {
    > font-size : 60%;
    > line-height : 22px;
    > list-style-image : url(images/bullet.gif);
    > list-style-position : outside;
    > text-align : left;
    > color : #66FFFF;
    > padding-top : 45px;
    > padding-left : 62px;
    > }
    >
    > #clear {
    > clear : both;
    > }
    > #footer {
    > background-image : url(images/footer_bground.gif);
    > width : 780px;
    > height : 80px;
    > margin-bottom : 10px;
    > margin-top : 10px;
    > position: fixed;
    > }
    > #footer p {
    > text-align : center;
    > font-size : 75%;
    > color : #66ffff;
    > padding-top : 24px;
    > }
    > #footer ul {
    > margin : 2px;
    > }
    > #footer li {
    > display : inline;
    > margin : 0;
    > }
    > #footer a:link, #footer a:visited {
    > color : #00ccff;
    > margin : 2px;
    > }
    > #footer a:hover, #footer a:active {
    > color : #00FFFF;
    > text-decoration : none;
    > background-color : #33cccc;
    > }
    > a:link {
    > color : #00ccff;
    > text-decoration : none;
    > }
    >
    > a:visited {
    > text-decoration : none;
    > color: #00CCFF;
    > }
    > a:hover {
    > text-decoration : underline;
    > color: #00FFFF;
    > }
    > a:active {
    > text-decoration : none;
    > color: #006699;
    > }
    >

  • Mixed results on iPad and iPhone 6 Plus with background image. How to fix this?

    Flash Professional CC
    I'm having an issue with adding images on iPhone 6 plus and iPad. I'm getting mixed results with two items: 1) a background image and 2) a button that should appear at the bottom left-hand corner on any device. In one case the background image appears enlarged and only shows about 30% of itself. In the other case, the bottom left-hand button appears about 50 pixels to the left when x=0. I also get different results when I set the following:
    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.align = StageAlign.TOP_LEFT;
    This does not produce the expected results. I would like to have consistent results across iPad and iPhone 6 plus, which seams to be an issue. The immediate fix for this is to leave the images on the stage instead of using addChild. I could then just stretch the background image so that it spans the whole screen. But I want to add the items dynamically for greater flexibility.
    Here are two cases:
    Case #1:
    This an iPhone 6 plus and you should notice 2 things. 1) There is black and white on both sides. The blue background SHOULD APPEAR ACROSS THE WHOLE SCREEN. 2) The red button in the corner SHOULD APPEAR IN THE LEFT MOST CORNER OF THE
    SCREEN.
    Case #2:
    This an iPhone 6 plus and I have set the scale X, Y to the stage.stageWidth/Height:
    mc_stageBackground_Main.scaleX = stage.stageWidth;
    mc_stageBackground_Main.scaleY = stage.stageHeight;
    This results in a close up of the background image.
    Here is the code that I'm using:
    import com.greensock.TweenLite;
    import com.greensock.easing.*;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    //When this is active the background image spans across the device (iPhone 6 plus) correctly. The main logo image does not line up correctly.
    /*stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.align = StageAlign.TOP_LEFT;*/
    var main_logo:MC_LOGO_MAIN = new MC_LOGO_MAIN();
    var mainBackground_2208: MC_MAIN_BACKGROUND_2208 = new MC_MAIN_BACKGROUND_2208();
    var mainBackground_1024: MC_BACKGROUND_1024 = new MC_BACKGROUND_1024();
    var mainCorner: MC_MAINCORNER = new MC_MAINCORNER();
    var chapters: MC_CHAPTERS = new MC_CHAPTERS();
    var _stageWidth = 1024;
    if (stage.stageWidth > _stageWidth)
        //Add bigger background if the stage is bigger than 1024
        mainBackground_2208.x = stage.stageWidth/2;
        mainBackground_2208.y = stage.stageHeight/2;
        addChild(mainBackground_2208);
        //Using this code results in a very close up view of the stage on iPhone 6 plus  
        /*mc_stageBackground_Main.scaleX = stage.stageWidth;
        mc_stageBackground_Main.scaleY = stage.stageHeight;*/
        //Adds corner to the main screen.
        mainCorner.y = stage.stageHeight;
        mainCorner.x = (stage.stageWidth - stage.stageWidth);
        addChild(mainCorner);
        TweenLite.from(mainCorner, 1,{ height: 0, width: 0, delay:1, ease:Elastic.easeOut});
        //add logo to sit at 50 pixels from the top of the stage
        /*main_logo.x = stage.stageWidth/2;
        main_logo.y = (stage.stageHeight -stage.stageHeight + main_logo.height *.6);
        addChild(main_logo);
        TweenLite.from(main_logo, 1,{ y: -main_logo.height, ease:Elastic.easeOut});*/
    else
        trace ("The stage is 1024 or smaller");
        //Add 1024 background if stage is 1024 or smaller
        mainBackground_1024.x = stage.stageWidth/2;
        mainBackground_1024.y = stage.stageHeight/2;
        addChild(mainBackground_1024);
        //Adds corner to the main screen.
        mainCorner.y = stage.stageHeight;
        mainCorner.x = (stage.stageWidth - stage.stageWidth);
        addChild (mainCorner);
        TweenLite.from(mainCorner, 1,{ height: 0, width: 0, delay:1, ease:Elastic.easeOut});
        //adds chapters
        chapters.x = (stage.stageWidth - stage.stageWidth)+75;
        chapters.y = stage.stageHeight - 120;
        addChild(chapters);
        TweenLite.from(chapters, 1,{ height: 0, delay:.5, ease:Elastic.easeOut});  
        //adds the Main logo to sit at 50 pixels from the top of the stage
        main_logo.x = stage.stageWidth/2;
        main_logo.y = (stage.stageHeight -stage.stageHeight + main_logo.height *.6);
        addChild(main_logo);
        TweenLite.from(main_logo, 1,{ y: -main_logo.height, ease:Elastic.easeOut});

    On all of the devices go to settings - facetime - iphone cellular calls - oFF, this part of Apple continuity.

  • How do you make a rectangle resize with background image?

    I'm trying to add links (transparent rectangles) to a background image that is set with "scale to fit". However when it scales in needs to scale with my links. Can I have the rectangles scale with the background image? If not is there a better way of doing this?

    As I understand. correctly.  You want the rectangles that you have added over background image, (to which links are added) to be responsive in layout within the project, Am I correct ? If yes ! Muse does not implement "Responsive Layout" as defined by a hand coder. For more details refer to : Can you create responsive sites with Adobe Muse?

  • Help with background image center position in firefox

    See here on
    firefox<<<
    i dont know whats going wrong, i tried many different ways
    with divs only but doesnt work...
    any help appreciated...
    css
    /* CSS Document */
    body {
    background-image:url("resources.jpg");
    background:url("resources.gif") no-repeat center;
    .textstyle01res {
    font-family:Verdana, Arial, Helvetica, sans-serif;
    font-size:62%;
    color:#FFFFFF !important;
    text-align:center;
    padding-top:360px;
    text-decoration:none;
    .textstyle01res a {
    color:#FFFFFF !important;
    text-align:center;
    padding-top:360px;
    text-decoration:none;
    html
    <!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" />
    <link href='res.css' rel="stylesheet" type="text/css"
    media="screen" />
    <title>Feast of Marriage - Resources</title>
    <style type="text/css">
    <!--
    body {
    background-color: #147972;
    -->
    </style>
    </head>
    <body>
    <div style="width:940px; height:140px;">
    </div>
    <div style="padding-left:227px;" align="center">
    <table width="200" border="0">
    <tr>
    <td><img src="res-a.jpg" border="0"
    alt=""/></td>
    </tr>
    </table>
    </div>
    </body>
    </html>

    css:
    table#centerTable {
    margin-left: auto;
    margin-right: auto;
    html:
    <body>
    <div style="width:940px; height:140px;"></div>
    <table id="centerTable" width="200" border="0">
    <tr>
    <td><img src="res-a.jpg" border="0"
    alt=""/></td>
    </tr>
    </table>
    </body>
    Lampros_uk wrote:
    >
    http://www.3ddream.net/feast/resources.html<<<
    > i dont know whats going wrong, i tried many different
    ways with divs only but
    > doesnt work...
    > any help appreciated...
    >
    > css
    > /* CSS Document */
    >
    >
    > body {
    > background-image:url("resources.jpg");
    > background:url("resources.gif") no-repeat center;
    > }
    >
    > .textstyle01res {
    > font-family:Verdana, Arial, Helvetica, sans-serif;
    > font-size:62%;
    > color:#FFFFFF !important;
    > text-align:center;
    > padding-top:360px;
    > text-decoration:none;
    > }
    > .textstyle01res a {
    > color:#FFFFFF !important;
    > text-align:center;
    > padding-top:360px;
    > text-decoration:none;
    > }
    > --------------
    >
    > html
    > <!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" />
    > <link href='res.css' rel="stylesheet" type="text/css"
    media="screen" />
    > <title>Feast of Marriage - Resources</title>
    > <style type="text/css">
    > <!--
    > body {
    > background-color: #147972;
    > }
    > -->
    > </style>
    > </head>
    > <body>
    > <div style="width:940px; height:140px;">
    > </div>
    >
    >
    > <div style="padding-left:227px;" align="center">
    > <table width="200" border="0">
    > <tr>
    > <td><img src="res-a.jpg" border="0"
    alt=""/></td>
    > </tr>
    > </table>
    > </div>
    > </body>
    > </html>
    >
    >

  • Vertical tabbed panel with background image

    Hi all,
    I have a working vertical tabbed panel.  For the text that's shown, there's a background image assigned to the associated DIV.
    However...
    The background image that's shown is clipped to the bottom of the text.
    In other words, if I have 3 lines of text, the bottom of the background image only goes as far down as the bottom line of text.  In order to show the entire image, I have to put in a lot of </ br> tags for "empty" text, not a very good approach.
    More of the backgound will show if I increase the text text size via the browser.
    To try to describe this more accurately,
    Let's say I have a background image that's 600 px in height, but the lines of text only measure to 400px.  That means that the bottom 200 px of the image doesn't show, unless I add more lines of text.
    Hoping someone has an answer!
    Thanks,
    Jerry

    Gramps,
    Again, thanks for your time.  While we're now full time commercial photographers (http://www.jerryandlois.com), I was a software engineer for some 20+ years in an earlier life, all on the application side of things.  Not really any appreciable time with website stuff.
    There are a few more tech/how-to questions I have that are specific to CSS, in terms of polishing up the small site I'm working on.  However these are not SPRY related, unless SPRY can solve this for me.
    In particular, suppose I have a large block with a background image and a body of text.  I want to ensure the text wraps around the image, rather than being a complete overlay where the text can collide with the main body of the photo.
    Example:
    http://jerryandloisstudios.com/about.html
    The issue is that the text is resizable, by design of course.  Is there any way to manage these two elements (text and image) so they get along the right way?  We want the text to overlay some of the image, but only on the periphery, if that makes sense.  So far, the only solution I've seen is to keep the text formatted roughly in a column so that if its size increases all will still be OK.  But...  artistically that just doesn't look right.
    If you're up for it, I'd certainly welcome a private email thread, unless others can also benefit from the rather newbie questions I'm raising:  [email protected]
    Again, thank you for your help!!!
    Jerry

  • Weird issue with background image (Safari)

    Just wonder if anyone can shed any light on this one....
    Basically have a design in progress here:
    http://www.hpwebdesign.co.uk/rachelworrall/index101.php
    All was fine until I added the three images that fade into one another using the Ultimate Fade In slideshow script ( http://www.dynamicdrive.com/dynamicindex14/fadeinslideshow.htm )
    When the page is initially loaded in Safari (5), the top section of the background image doesn't display - it starts just beneath the main content below the navigation.
    The weird part is that it literally only takes a click of the mouse outside that Safari window to make it appear. A refresh, however, won't.
    It seems fine in Firefox on a Mac, and the client didn't report any issue in IE.
    Can anyone with Safari have a quick look and replicate that glitch? If not, then it might just be some weird local issue here.
    Many thanks.

    I've put up a couple of screenshots here:
    http://www.hpwebdesign.co.uk/rachelworrall/screenshots.htm
    Its like that in Safari 5.0.3 (and 5.0.4 which I've just updated.)
    Again, it literally just needs a click out of the Safari window to make it appear correctly as per the second screenshot.
    Its like this on a 27" iMac, but had a look on the macbook, and its fine on there.
    So if it looks OK with anyone else, I'm just going to put it down to a weird glitch on my machine here.

Maybe you are looking for

  • Personalization to Pop up a Note for Duplication of line item

    Hi, I need a help in one of our requirement. We want to throw a Note message to indicate that the same item is used in that purchase order whenever the same item is entered in more than one line. Thanks in Advance, Venkat.

  • Help restore the lost work

    If you can tell me. My situation is this. After several surges computer rebooted and since then in the "incoming" = "inbox" messages are not displayed. At C: \ \ Documents And Settings \ $ user \ Local Settings \ Application Data \ Identities \ {...}

  • How to Maintain Relation for tables

    Hi All, Can anybod help me how maintain relationship/ connectivity for purchase order between (ekko- ebeln) and Handling unit (vekp-exidv). Here I need to fetch the HU details based on the purchase order. Please through some light on this. regards, A

  • Digital camera/iPod question

    Today I travel with my family from Honolulu to Puna, Hawaii to look at the possibility of buying a home there. I was wondering if it is possible to transfer pics from digital camera to iPod directly without the use of a my Mac? I'm not sure I want to

  • How to check Organizational Unit

    Hi experts, How many ways are there to check the organizational unit of an User? (i need Tcodes or tables to check) Thanks in advance