CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2000
    Posts
    4

    show a image.gif as background

    i'm programming a application in JAVA with JBuilder and i need to know if it's possible to display a image.gif as background instead of the usual Color
    ...and if it's possible ... wath is the source code to program such a thing.....



  2. #2
    Join Date
    Dec 1999
    Location
    Chonghe, Taipei County, Taiwan, R.O.C.
    Posts
    231

    Re: show a image.gif as background

    You may use Component.getGraphics() to get the Graphics object
    and use Graphics.drawImage() to paint your image in the background.
    Of course, you may load your image in advance.
    good luck
    Alfred Wu


  3. #3
    Guest

    Re: show a image.gif as background

    Hi,friends:
    I am new java programmer. I have the same problem. How can i change the background of a button to an image when I press this button?

    Cna anybody tell me where can i find the source code like this?

    thank you very much!


  4. #4
    Guest

    Re: show a image.gif as background

    I had this problem months ago... and searched this database extensively...

    Here is my response which works well..


    JBackgroundPanel jbp;
    .
    jbp = new JBackgroundPanel(Toolkit.getDefaultToolkit().getImage("images/loginbg1.jpg"));
    GridBagLayout gridbag = new GridBagLayout();
    jbp.setLayout(gridbag);
    jbp.add(User); //where these are JTextfields
    jbp.add(Pass);
    Win.getContentPane().add(jbp); //displayed in window but any container will work
    .
    .
    .
    class JBackgroundPanel extends JPanel { Image im;
    JBackgroundPanel(Image im) { super(); this.im = im; }
    public void paintComponent(Graphics g) { g.drawImage(im,0,0,this); } }


    And for futher info check out this ...
    http://forum.java.sun.com/[email protected]^[email protected]/0


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured