DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2005

    Background image

    I am trying to get a lot of JButtons to display on top of a background image of the world in a JFrame.
    So far, I've tried a lot of things. I tried overwriting the paint function of the JFrame to drawImage the image of the world. But whenever I repainted, the buttons got painted very quickly and then covered by the background image.
    I then tried to create a JLayeredPane. Here is an excerpt of the code:

    Dimension layeredPaneSize = new Dimension(1025, 740);
    JLayeredPane layeredPane = new JLayeredPane();

    JButton myWorldButton = new JButton (big_world);
    myWorldButton.setBounds (10, 10, 1000, 700);
    layeredPane.add(myWorldButton, JLayeredPane.DEFAULT_LAYER, 0);

    tmp1 = 0;
    tmp2 = 0;
    for (int s = 0; s < 5; ++s)
    world[s].myButton.setBounds(tmp1,tmp2, 8, 8);
    layeredPane.add(world[s].myButton, JLayeredPane.POPUP_LAYER, 0);
    tmp1 = tmp1 + 10;
    tmp2 = tmp2 + 10;

    Checkbox less_than = new Checkbox (" <");

    less_than.setBounds(20, 650, 10, 10);

    layeredPane.add(less_than, JLayeredPane.MODAL_LAYER, 0);


    And the only thing that happens is that the checkbox displays. Does anybody have any idea how I should proceed/what I'm doing wrong? Please let me know. Thanks

  2. #2
    Join Date
    Nov 2004
    The only way to do this (using std. components and overwriting the
    paint/update) that I know of is to set the layout for the container (frame) to null,
    use the setBounds(x,y,w,h) for each component (button) that is added to the
    container, and to overwrite the update method where only the background image is

    In general, mixing the default container layout/paint job with ones own
    paint/update implementations seems to be a bad idea. Its a very frequent
    issue in this forum.

    I beleive that the best to do in such cases is to implement ones own buttons,
    i.e. coding graphical objects with the desired responsiveness and layout.
    Once done, these can be reused.
    Last edited by sjalle; 07-13-2005 at 10:19 AM.
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center