How can I create a single background image for a BorderLayout?

I can create a background with an image file for the individual panel (North, West, Center, East and South) in a BorderLayout, but I've been spinning my wheel for a long while now trying to figure out how to create just one background with a single image file for all of these panels?
In my application, a panel may contain various buttons, a listbox, a group of checkboxes, a combo box, or a canvas. Even if I used the same image file, when the panels are finally put together, one can clearly see that the end product is the result of a lot of patch works.
Hope someone has an answer for this. BTW, I'm using AWT because it works with existing browsers without the need for a separate Java plug-in.
Regards,
V.V.

Look at this :
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.awt.image.BufferedImage;
public class PanI extends Frame
     Image map;
     Panel pan;
     myPan p8,p4,p6,p2,p5;
     BufferedImage I;
public PanI() 
     addWindowListener(new WindowAdapter()
    {     public void windowClosing(WindowEvent ev)
          {     dispose();
               System.exit(0);}});
     map = getToolkit().getImage("map2.gif");
     MediaTracker tracker = new MediaTracker(this);
     tracker.addImage(map,0);
     try   {tracker.waitForID(0);}
     catch (InterruptedException e){}
     I = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB);
     setBounds(10,10,map.getWidth(null)+8,map.getHeight(null)+27);
     setLayout(new BorderLayout());
     pan = new Panel();
     add(pan,BorderLayout.CENTER);
     pan.setLayout(new BorderLayout());
     pan.setSize(map.getWidth(null),map.getHeight(null));
     p5 = new myPan(5);
     p5.setBackground(Color.red);
     pan.add(p5,BorderLayout.CENTER);
     p8 = new myPan(8);
     p8.setBackground(Color.orange);
     pan.add(p8,BorderLayout.NORTH);
     p4 = new myPan(4);
     p4.setBackground(Color.blue);
     pan.add(p4,BorderLayout.WEST);
     p6 = new myPan(6);
     p6.setBackground(Color.green);
     pan.add(p6,BorderLayout.EAST);
     p2 = new myPan(2);
     p2.setBackground(Color.pink);
     pan.add(p2,BorderLayout.SOUTH);
     setVisible(true);
public class myPan extends Panel
     int where;
public myPan(int i)
     super();
     where = i;
public void paint(Graphics g)
     if (I.getWidth(null) != pan.getWidth() || I.getHeight(null) != pan.getHeight())
          I = new BufferedImage(pan.getWidth(),pan.getHeight(),BufferedImage.TYPE_INT_ARGB);
          Graphics      G = I.getGraphics();
          G.drawImage(map,0,0,pan.getWidth(),pan.getHeight(),null);     
          G.dispose();
     int x1=0;
     int x2=getWidth();
     int y1=0;
     int y2=getHeight();
     if (where == 8)
     if (where == 2)
          y1 =  p8.getHeight()+p5.getHeight();
          y2 =  getHeight()+y1;
     if (where == 4)
          y1 =  p8.getHeight();
          y2 =  y1+getHeight();
     if (where == 5)
          x1 =  p4.getWidth();
          x2 =  x1+getWidth();
          y1 =  p8.getHeight();
          y2 =  y1+getHeight();
     if (where == 6)
          x1 =  p4.getWidth()+p5.getWidth();;
          x2 =  x1+getWidth();
          y1 =  p8.getHeight();
          y2 =  y1+getHeight();
     g.drawImage(I,0,0,getWidth(),getHeight(),x1,y1,x2,y2,null);
public void update(Graphics g)
     paint(g);
public static void main (String[] args) 
     new PanI();
Noah

Similar Messages

  • How can I create an alt background color for items in a jlistbox or jtree

    What I'm looking to do is have a white background for say items 1,3,5, etc. and a light yellow background for items 2,4,6, etc. I was wondering how can I set an alternative background color on items in a JTree or a JList

    Use a cell renderer:
    import java.awt.*;
    import javax.swing.*;
    public class ListAlternating extends JFrame
         public ListAlternating()
              String[] items = {"one", "two", "three", "four", "five", "six", "seven"};
              JList list = new JList( items );
              list.setVisibleRowCount(5);
              list.setCellRenderer( new MyCellRenderer() );
              JScrollPane scrollPane = new JScrollPane( list );
              getContentPane().add( scrollPane );
         public static void main(String[] args)
              ListAlternating frame = new ListAlternating();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible( true );
         class MyCellRenderer extends DefaultListCellRenderer
              public Component getListCellRendererComponent(
                   JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
                   super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                   if (!isSelected)
                        setBackground(index % 2 == 0 ? list.getBackground() : Color.LIGHT_GRAY);
                   return this;
    }

  • How can I create a java.awt.Image from ...

    Hi all,
    How can I create a java.awt.Image from a drawing on a JPanel?
    Thanks.

    JPanel p;
    BufferedImage image =
        new BufferedImage(p.getWidth(), p.getHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = image.createGraphics();
    p.paint(g);
    g.dispose();

  • How can I create a high res image gallery, need to have print res photos for a pressroom section.

    How can I create a high res image gallery, need to have print res photos for a pressroom section.

    If you want Muse to "pass through" your images and not adjust, compress, crop etc - you need to place your images in the lightbox EXACTLY at the right size, pre-cropped and prepped in Photoshop.
    So if your light box is 800x600 the image you're dropping into that must be 800x600 exactly with no effects, rotation etc added to the lightbox frame. This stop Muse fiddling with your images, if they are perfect when inserted and you're not asking Muse to crop, expand, add effects etc. If it's perfect when inserted, Muse SHOULD also leave the resolution alone too, but I have not tried that one, but in theory, it should work.

  • How can I create a single order from multiple quotations?

    How can I create a single order from multiple quotations that I have created by the transaction VA21 ?
    Thanks in advance for the answers.

    hi
    Go to transaction: /nva01
    Enter order type : ZOR
    Sale org :xxxx
    Dist.channel:xx
    Division :xx
    Press enter
    Click on “Sale document” and select Create with reference
    Then enter 1st quotation number & click on “COPY” or “Selection list”. Then click on “Copy “.Then all line items which belong to quoation1 copy to order.
    Then,
    Click on “Sale document” and select Create with reference
    Then enter 2nd quotation number & click on “COPY” or “Selection list”. Then click on “Copy “.Then all line items which belong to quoation2 copy to order.
    Then,
    Click on “Sale document” and select Create with reference
    Then enter 3rd quotation number & click on “COPY” or “Selection list”. Then click on “Copy “.Then all line items which belong to quoation3 copy to order.
    Now save the sale document.
    Kindly give reward points
    Edited by: WISH on Mar 19, 2008 2:25 PM

  • How can I create a start up disk for a old intel core duo running 10.5.8.. Computer works fine, but can't find install disk.

    How can I create a start up disk for a old intel core duo running 10.5.8.. Computer works fine, but can't find install disk. Want to use internal disk drive or USD flash drive.

    Try calling 1-800-676-2775.  Give the serial number and thy *may* still burn you new install disks designed just for the hrdware in your system (for a fee, something like $160 per disk).  *May* is only because they may not burn disks for Leopard anymore.
    If they do not burn them for you, you can buy Leopard disks off Amazon or eBay for about $200.
    Have you considered Snow Leopard?.  Those disks only cost $19 (single user) or $29 (5-user license) through Apple by calling 1-800-MY-APPLE.

  • How can I create a new ring tone for my iPhone 4?

    How can I create a new ring tone for my iPhone 4? I followed the Garage Band process and ended up with the ring tone I want as a AAC audio file. It got stored in my iTunes a a song rather than a ring tone. How do I make it a ring tone vs. a song? I tried dragging it t the Ring Tone category at the bottom of the ITunes list, but it won't alloow me to move it?

    There's also an easy to use Applescript over at Doug's Applescripts for iTunes. It automates the whole thing. All you do is set the start and stop time on a file in iTuens and run the script. It will do everything else.
    Make Ringable v1.1
    http://dougscripts.com/475

  • How can I create a sub-iTunes account for a teen?

    how can I create a sub-iTunes account for a teen?
    I need to separate our music libraries but still keep it under control from the main account (mine).

    iOS 5 & iCloud Tips: Sharing an Apple ID With Your Family

  • How can I create a magazine web app for all devices?

    How can I create a magazine web app for all devices?

    magazine web app is not supported in DPS as of now. You can share the contents to preview it on web content viewer.

  • How can i create a bootable usb sata for xp

    how can i create a bootable usb sata for xp

    Installing Windows XP on a portable USB hard drive is not supported.
    Carey Frisch

  • I have an iCloud email address on my iMac. How can I create an icloud email address for my wife on the same computer?

    I have an iCloud email address on my iMac. How can I create an icloud email address for my wife on the same computer?

    If all you want is an additional email address you can create up to three 'email aliases'  - these are additional addresses (not accounts) which deliver into the same inbox as the main account.
    You should be aware before you start that once you've created an alias you cannot turn that address into a full iCloud account, move it to another account, or reactivate it if you delete it.
    More information on aliases here:
    http://help.apple.com/icloud/#mm6b1a490a
    If you want to keep her email separate from yours she will need to create a new Apple ID, and use it to create a new iCloud account either on a separate computer or on a separate User Account on your Mac.

  • How can i create the blue "I"-Button for the Documentation in a view

    How can i create the blue "I"-Button for the documentation in a view?
    I want to prepare the button with user specified Information...
    and where must be create the documentation?
    thanks
    Edited by: DDC-TD on Apr 24, 2008 10:22 PM

    you have not mentioned where do u want the " I " information button ,
    1. If u want for a report , u can get the information button on selection-screen only .
       if u goto se38 on the mail screen u will find a radio button for documentaion ,
    when u select it and click 'create' or 'change' , an editor will open and u can document anything there ....
    2. Or specify where u want  info button .
    thanks ,
    reward points if usefull.

  • How can i create datasource on apache server for ADF application?

    Hi All,
    i my use case i have created simple adf application using ADF BC and want to deploy on Apache server 6.x.
    So my question is that  how can i create Data Source i have goggling and find  two different way to do this.
    1. write following line of code on apache server conf/Context.xml file.
    <Resource name="jdbc/TestDB" auth="Container"
                  type="javax.sql.DataSource"
                   driverClassName="oracle.jdbc.OracleDriver"
                  url="jdbc:oracle:thin:@localhost:dst"
                  username="jagrandb" password="jagrantest" maxActive="20" maxIdle="10"
                  maxWait="-1"/>
    but when i have used this way i got following exception.
    org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to oracle.jdbc.OracleConnection
    check link-
    https://forums.oracle.com/thread/2564233
    2. write following line of code apache conf/Server.xml file
    <GlobalNamingResources>
        <!-- Editable user database that can also be used by
             UserDatabaseRealm to authenticate users
        -->
        <Resource name="UserDatabase" auth="Container"
                  type="org.apache.catalina.UserDatabase"
                  description="User database that can be updated and saved"
                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                  pathname="conf/tomcat-users.xml" />
    <Resource name="jdbc/TestDB" auth="Container"
                  type="oracle.jdbc.pool.OracleDataSource"
                  description="User database that can be updated and saved"
                  driverClassName="oracle.jdbc.driver.OracleDriver"
                  factory="oracle.jdbc.pool.OracleDataSourceFactory"
                  url="jdbc:oracle:thin:@//172.31.43.207:1521:dst"
                  username="jagrandb" password="jagrantest" maxActive="20" maxIdle="10"
                  maxWait="-1"   />
      </GlobalNamingResources>
    and add this line in context.xml file inside <context> tag
    <ResourceLink global="jdbc/TestDB" name="jdbc/TestDB" type="oracle.jdbc.pool.OracleDataSource"/>
    but when i have run application i have got following error
    log-
    javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: invalid arguments in call"
      at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:298)
      at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:181)
      at org.apache.jsp.test_jsp._jspx_meth_sql_005fquery_005f0(test_jsp.java:110)
      at org.apache.jsp.test_jsp._jspService(test_jsp.java:63)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
      at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:857)
      at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:565)
      at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509)
      at java.lang.Thread.run(Thread.java:662)
    Aug 2, 2013 5:17:21 PM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet jsp threw exception
    javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: invalid arguments in call"
      at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:298)
      at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:181)
      at org.apache.jsp.test_jsp._jspx_meth_sql_005fquery_005f0(test_jsp.java:110)
      at org.apache.jsp.test_jsp._jspService(test_jsp.java:63)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
      at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:857)
      at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:565)
      at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509)
      at java.lang.Thread.run(Thread.java:662)
    so what is the solution how to create datasource on apche server which suitable for adf application?
    when i test data source using  following code used 1. way as i mentioned above  its running fine bt not for second.
    <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <sql:query var="rs" dataSource="jdbc/TestDB">
    select empname from pay_emphdr where empcd='JK1306'
    </sql:query>
    <html>
      <head>
        <title>DB Test</title>
      </head>
      <body>
      <h2>Results</h2>
    <c:forEach var="row" items="${rs.rows}">
        Foo ${row.empname}<br/>
    </c:forEach>
      </body>
    </html>
    please help me. it is very urgent.
    thanks in Advance
    Manish

    Hi Lindalnci
    i have already tried  this tutorial and in my post i have defined first way to do using this procedure.
    in that case i have got following exception as i have mentioned above
    org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to oracle.jdbc.OracleConnection

  • How can I create a folder in ios for pdf files?

    How can I create a separate folder in ios for my pdf files?

    Hi Artistdeet,
    For this you have to follow certain steps-
    1. Tap on Document tab from left pane of Adobe Reader.
    2. Tap on 'Edit' button placed at right side of top toolbar.
    3. Tap on "folder icon with plus sign", it will ask you to enter the folder name.Enter desired folder name by which you want to create the folder.
    Hope this will solve your problem.
    Thanks
    -Satyadev

  • How can I create a bootable DISK IMAGE of my PB Internal Drive?

    I would like to make a bootable image of my Hard Drive but without including any Free Space.
    You see all I need on the image are the OSX and the programs, NOT the 60GB of Free Space. Disk Utility however wants to create a 80gb image which includes 60GB of Free Space.
    I would like to use the Bootable image as a source image to use with the RESTORE function in Disk Utility.
    Regards

    You'll need a second machine or an external HDD with Mac OS X installed on it.
    For purposes of this procedure I'll be calling your machine the 'source' and the second machine or your external HDD the 'target'.
    First either boot the source into target mode by holding down the 'T' key while it boots. Once you see the FireWire icon on the screen, let go of the 'T' key and plug the source into the target. If you're going with the external HDD route, boot your source of off your external HDD.
    Now, select the drive of your source machine, and hit Apple-I to bring up the information pane. Down at the bottom (in the permissions area) you'll see a check box labeled "Ignore ownership..." Uncheck that.
    Open up Disk Utility. Select the source drive and run First Aid and Repair Permissions on it.
    Now, select the File menu -> New -> New Disk Image from Folder. You're going to want to hit that big "New Image" button, but don't. Trust me. It'll only cause trouble for you down the road.
    Select the source drive as the source. You can leave everything else the same and click "Image".
    Select the target as the destination. Click Save.
    Wait for a couple of hours (depending on how much stuff you have).
    When it's done, select the Images menu -> Scan image for Restore.
    Select the disk image you just made and click "Scan".
    When that's done you have a restorable image. Just use the restore tab to restore it.
    I've done this literally hundreds of times and it's worked every single time.

Maybe you are looking for