Results 1 to 2 of 2
  1. #1
    enerj is offline Member
    Join Date
    Sep 2010
    Posts
    30
    Rep Power
    0

    Default Putting one JPanel on top of another, can't get rid of gap at top

    I am making a simple program for fun, where I want to have one panel, the back panel, with a mouse listener on it, and one panel in front of it, the front panel, that will display an image.

    The end goal is to have the user be able to click on the panel, the applet will process the information and give the point to the front panel, which will then draw the point, on it's own graphics object in paintComponent. Therefore it is very important that the two panels coincide perfectly, so the the point drawn is at the same location as the one passed in.

    Unfortunately I have a gap between my two panels, at the top, about 5 pixels or so. In the picture below, the back panel is drawing a red rectangle over it's entire area, and the front panel is displaying the picture. My x points work fine, as they both line up. However when the front panel draws the point, it is lower than where the mouse click occurs, because of this misalignment.

    Does anyone have any idea where this is coming from, or how to remedy? Thanks in advance.



    Picture explanation - The back panel and front panel are both contained inside another panel, represented by the blue rectange. The front panel was simply added to the back panel, which was added to the other 'subpanel' which has another panel down at the bottom, and it's setup in a box layout y-axis.

  2. #2
    enerj is offline Member
    Join Date
    Sep 2010
    Posts
    30
    Rep Power
    0

    Default

    Fixed it by changing the back panels layout to a y-axis boxlayout.

Similar Threads

  1. Putting graphics into the run() method.
    By theCardboardBox in forum New To Java
    Replies: 11
    Last Post: 11-17-2010, 06:33 PM
  2. Putting Applet on web with images
    By Peetahzee in forum New To Java
    Replies: 1
    Last Post: 04-18-2010, 08:35 PM
  3. Putting a graph on another JPanel in another JFrame
    By thestarncy in forum AWT / Swing
    Replies: 10
    Last Post: 12-31-2009, 04:45 PM
  4. Putting code together.
    By newbee in forum New To Java
    Replies: 3
    Last Post: 04-17-2008, 03:53 AM
  5. Putting your own type in a Set
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-15-2008, 07:32 PM

Posting Permissions

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