Moving canvas or panel over image

Hello!
Let's say I have a class that extends from panel, and in the paint method i draw an image on the panel. Now I need another object, transparent, but with some graphics on it, let's say a canvas, or another panel, with a rounded rectangle drawn inside, but otherwise transparent. Now I want to move that other canvas on the original panel panel, and i want original image to be seen where the canvas is transparent. How can I do this? How can I make such a canvas and add it to the panel?

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
public class OverlayTest extends JPanel
    BufferedImage image;
    public OverlayTest()
        loadImage();
    protected void paintComponent(Graphics g)
        super.paintComponent(g);
        int w = getWidth();
        int h = getHeight();
        int imageWidth = image.getWidth();
        int imageHeight = image.getHeight();
        int x = (w - imageWidth)/2;
        int y = (h - imageHeight)/2;
        g.drawImage(image, x, y, this);
    private void loadImage()
        String fileName = "images/redfox.jpg";
        try
            URL url = getClass().getResource(fileName);
            image = ImageIO.read(url);
        catch(MalformedURLException mue)
            System.err.println("url: " + mue.getMessage());
        catch(IOException ioe)
            System.err.println("read: " + ioe.getMessage());
    public static void main(String[] args)
        JPanel panel = new JPanel();
        OverlayLayout overlay = new OverlayLayout(panel);
        panel.setLayout(overlay);
        panel.add(new TopPanel());
        panel.add(new OverlayTest());
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(panel);
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
class TopPanel extends JPanel
    Point loc;
    int width, height, arcRadius;
    Rectangle r;       // for mouse ops in TopRanger
    public TopPanel()
        setOpaque(false);
        width = 300;
        height = 240;
        arcRadius = 35;
        r = new Rectangle(width, height);
        TopRanger ranger = new TopRanger(this);
        addMouseListener(ranger);
        addMouseMotionListener(ranger);
    protected void paintComponent(Graphics g)
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        if(loc == null)
            init();
        g2.setPaint(Color.red);
        g2.drawRoundRect(loc.x, loc.y, width, height, arcRadius, arcRadius);
    private void init()
        int w = getWidth();
        int h = getHeight();
        loc = new Point();
        loc.x = (w - width)/2;
        loc.y = (h - height)/2;
        r.x = loc.x;
        r.y = loc.y;
class TopRanger extends MouseInputAdapter
    TopPanel top;
    Point offset;
    boolean dragging;
    public TopRanger(TopPanel top)
        this.top = top;
        offset = new Point();
        dragging = false;
    public void mousePressed(MouseEvent e)
        Point p = e.getPoint();
        if(top.r.contains(p))
            offset.x = p.x - top.r.x;
            offset.y = p.y - top.r.y;
            dragging = true;
    public void mouseReleased(MouseEvent e)
        dragging = false;
        // update top.r
        top.r.x = top.loc.x;
        top.r.y = top.loc.y;
    public void mouseDragged(MouseEvent e)
        if(dragging)
            top.loc.x = e.getX() - offset.x;
            top.loc.y = e.getY() - offset.y;
            top.repaint();
}

Similar Messages

  • Unable to set a transparent panel over Images for annotations

    Hi All,
    I am developing a Swing Application for image processing.
    My aim is to display the image on a JPanel and over which the user should be able to draw different geometrical figures(line,circle,polygons,etc) and write annotations on that. These drawings should not affect the original image.
    Also, these drawings should be movable, like if I zoom the image, drawings over the image should also zoom in the same ratio.
    Initially, I thought of using the GlassPane but stuck up with some issues, relating to its implementation.
    It would be great, if you could suggest me some guidelines or pont me to some resources for the same.
    Any help in this regard will be highly appreciated.
    Thanks,
    Manu
    Edited by: manu_agarwal on May 8, 2009 12:46 PM

    Hi Adam,
    Thanks for your reply.
    My intention is that after draing annotations on the image, if the user wants to zoom or move image(panning), the annotations should also move.
    Thanks,
    Manu

  • DW CC Fluid grid transparent text panels over media content?

    Hi,
    I want to add some text panels similar to this website over images and other media content such as video clips:
    http://roedesigns.com/easy-css-only-image-description-hover/
    I don't need it to hover, I just want to add a transparent text panel like in the link over a picture or video.
    The website i'm working on is Fluid so is this something I need to do with CSS or JQuery.?
    What would be the code for something like that?
    At the moment I have a new section with a 'article' object/div set up for the content, the content will be a image with the text panel or a video with the text panel.
    <article class="fluid article">INSERT PIC/VIDEO HERE</article>
    help much appreciated!

    See this updated Fiddle:
    Edit fiddle - JSFiddle
    Nancy O.

  • File Path Visible When I Hover Over Images

    Hi,
    I converted a PowerPoint document to a PDF. The PowerPoint document includes images (GIF, JPEG). When I hover my cursor over the image in the PDF I created I can see the file path C:\User\User Name\Photo\File Name.JPG.
    Is there a setting in the PDF that I can 'unselect' so I don't see the file path when I hover over images?
    Thanks,
    mindforge

    Please try the suggestions mentioned here : http://forums.adobe.com/message/3364072#3364072
    Regards,
    Deepak

  • How to connecttwo external 19" LCD panels over DVI to MBP

    Hi,
    Is it possible to connect two 19" LCD panels over DVI to a MBP and run them as a single extended desktop?
    I've not been able to find an answer in the many posting and I get the impression its possible, but I'm not sure. I get more doubtful when I start to figure out how to do the cabling (daisy-chain the panels, use a DVI splitter?).
    Any help is greatly appreciated!
    F

    Do you use this set-up with multiple monitors and the extended desktop?
    I ask because I followed your suggestion but at the Matrox site (http://www.matrox.com/graphics/en/cadgis/products/th2go/th2go.php) all the indications are that it only works with Windows. Even the user handbook doesn't reference Apple at all.
    It sounds like a great idea, but I'd like to verify it works before spending the $300.
    Francis

  • Over image not working in Nav Bar

    I have established Up and Over images for my nav bar. The Up
    image is all that shows -- even when I mouse-over or click on the
    button. Thanks for your help!
    Jim
    "MM_nbGroup('down','group1','WhatWeDo','Images_and_Video/WhatWeDo_Over.gif',1)"
    onmouseover="MM_nbGroup('over','WhatWeDo','Images_and_Video/WhatWeDo_Over.gif','Images_an d_Video/WhatWeDo_Over.gif',1)"
    onmouseout="MM_nbGroup('out')"><img
    src="Images_and_Video/WhatWeDo_Up.gif" alt="Home page link"
    name="WhatWeDo" width="161" height="39" border="0" id="Home"
    onload="" /></a></td>
    </tr>
    <tr>
    <td><a href="whoweare.html" target="_top"
    onclick="MM_nbGroup('down','group1','WhoWeAre','Images_and_Video/WhoWeAre_Over.gif',1)"
    onmouseover="MM_nbGroup('over','WhoWeAre','Images_and_Video/WhoWeAre_Over.gif','Images_an d_Video/WhoWeAre_Over.gif',1)"
    onmouseout="MM_nbGroup('out')"><img
    src="Images_and_Video/WhoWeAre_Up.gif" alt="Who we are navigation
    link" name="WhoWeAre" width="161" height="39" border="0" id="Test"
    onload="" /></a></td>

    I'm sorry to tell you that the first thing you need to do is
    to get rid of
    the method you have used. It's quite antique, and was
    designed for framed
    pages. It adds quite a bit of additional code (some of which
    is invalid) to
    your page than would the alternative of using just ordinary
    image swaps for
    your menu.
    So, just create your menu from the up images in each row, and
    use DW's Swap
    image behavior on each.
    And put some duct tape over this NavBar option so that you
    don't use it
    again!
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "JRStaf4ord" <[email protected]> wrote in
    message
    news:gb85gs$5e$[email protected]..
    >I have established Up and Over images for my nav bar. The
    Up image is all
    >that
    > shows -- even when I mouse-over or click on the button.
    Thanks for your
    > help!
    >
    > Jim
    >
    >
    >
    "MM_nbGroup('down','group1','WhatWeDo','Images_and_Video/WhatWeDo_Over.gif',1)"
    >
    onmouseover="MM_nbGroup('over','WhatWeDo','Images_and_Video/WhatWeDo_Over.gif','
    > Images_and_Video/WhatWeDo_Over.gif',1)"
    > onmouseout="MM_nbGroup('out')"><img
    > src="Images_and_Video/WhatWeDo_Up.gif" alt="Home page
    link"
    > name="WhatWeDo"
    > width="161" height="39" border="0" id="Home" onload=""
    /></a></td>
    > </tr>
    > <tr>
    > <td><a href="whoweare.html" target="_top"
    >
    onclick="MM_nbGroup('down','group1','WhoWeAre','Images_and_Video/WhoWeAre_Over.g
    > if',1)"
    >
    onmouseover="MM_nbGroup('over','WhoWeAre','Images_and_Video/WhoWeAre_Over.gif','
    > Images_and_Video/WhoWeAre_Over.gif',1)"
    > onmouseout="MM_nbGroup('out')"><img
    > src="Images_and_Video/WhoWeAre_Up.gif" alt="Who we are
    navigation link"
    > name="WhoWeAre" width="161" height="39" border="0"
    id="Test" onload=""
    > /></a></td>
    >

  • Setting the order of a roll over image in a quiz

    Hi,
    I'm using captivate 4 and having issues in setting a quiz for my students.
    I want to have an icon to roll-over so the students can access information relating to the question, eg, diagrams, tables, graphs etc.
    I have done all this yet when the roll over image appears its order is set behind the question and answers, I need it in front. when trying to change the order, eg bring to front, all the options are grayed out and not available. Is there a way to fix this as I know I cannot use a slidelet in a question slide.
    I have also tried to re-order the question and answer text, but is is also grayed out.
    Any help would be greatly appreciated
    Cheers
    Andrew

    Hello,
    You cannot insert interactive objects on any default question slide from pool or not. You will have to change the action to be executed on Success/Failure. There it is possible to jump to a slide.
    Beware: you can never jump to a slide that is outside of the quiz 'scope'. This scope starts with the slide where you have the first scoreable object, which can be a question slide but also a button/click box/TEB with a score. The scope typically ends with the score slide. So be sure that the slide you want to jump to are in that scope. Eventually you can add a scoreable object (with a low score perhaps of 1pt) like a button or click box to the first slide of your project. If you keep the score slide as the last slide you will not have to worry anymore about the scope.
    Hope this makes sense,
    Lilybiri

  • Lines over images and around text in Captivate SWF file

    My project works & views fine in captivate and when published, it views fine on my mac - through flash player and browsers. But when I send a swf file to the client to view they see odd lines above and below images.
    But they dont see the lines when they view the htm file within a browser - then it views fine.
    The lines only appear when there's text over an image.
    Screen shots attached.
    My captivate project was created by importing a Powerpoint document, with images and text on each slide.
    I've changed the optimisation / slide quality through prefrences and on each slide to the highest quality.
    I've also un-selected the advanced slide compression.
    Is there another thing I can try to iron out these lines?
    Some of the images within Powerpoint are stretched, would this cause the lines?
    Is it a flash player issue?
    Or a zooming issue?
    Any help is much appreciated!

    Thanks Lilybiri,
    I am a new user & just finding my way
    I understand how to publish and how Captivate creates a zipped file with a SWF, HTML, JS and CSS files etc. (Im using Captivate 7). 
    How do you send Captivate projects to clients for review / approval before you supply them with the whole project zipped file?
    So far I've been sending them the swf file to check. And have had troubles with them viewing the lines over images and around text. Even though I cant see the lines.
    I need the client to see what I'm seeing - a project without any lines.

  • Insert shape over image in table cell

    Want to use circles, ovals, lines with arrows to point to some part (text or image) of a cell in a table.
    Need to emphasize certain areas of graphics in a document used as a step by step type document.
    If I add the shape outside the table and then try to drag/drop on to the image in the cell, the entire cell jumps to a new empty cell.
    Can nod get image to appear over the image in the table cell.

    Hello,
    do you think about this, please have a look here: http://help.adobe.com/en_US/dreamweaver/cs/using/WSc78c5058ca073340dcda9110b1f693f21-7b86a .html.
    Another way, to add text over an image uses Nancy O.'s Demo here (I would prefer by using PS or similar):
    http://alt-web.com/DEMOS/CSS-Sold-Out-Text-over-image.shtml
    Hans-Günter

  • Translucent gray over image in thumbnil (grid) view

    See example image below:
    one thumbnail looks OK (on left), but other, problem image (on right) has translucent gray layer over image!
    The problem images are not in a stack.
    If I click the problem image thumbnail it looks normal, but the gray overlay re-appears if I click on anther image.
    It shows OK in develop module.
    I know this is probably something stupid, but...can anyone help identify what is happening?
    -Colin

    Most probably you have flagged the image as "rejected" by pressing "X" on your keyboard.
    When an image is flagged as rejected it gets that grey overlay that disappears when you select the image. You can still edit them in the Develop Module.
    To delete the "Rejected" flag, select the images with the grey overlay and press "U" or "P" on your keyboard. "U" stands for "Unflagged". "P" stands for "Picked".

  • Draw line over Image??.. in Grid Format

    Hello frnds,
    what i want to do in my project is to draw image on JPanel with grid lines.. ??
    May be image in background and lines over image..
    I searched forum before but coulnt find appropriate thread.. please help me out??
    gervini

    from within the JPanel's paint() method.In Swing components you should overide the paintComponent() method, not paint().

  • Roll-over images

    Does RoboHelp support roll-over images?
    I've tried every way to insert a roll-over image into my
    project, including editing the html page in dreamweaver but as soon
    as I open it up in RoboHelp and generate it the images either does
    not change or it is not visible.
    Please advise...
    Thanks,
    Susy Carrillo

    You might take a look at
    Walter
    Zorn's free tooltip utility, a really neat onMouseover
    application that makes your tooltips look like popups, including
    the use of links within them.
    You can use it for text links or in combination with image
    maps. So far, I'm using only the former, but I'll be using the
    latter for some new, complex C# screens in our next version
    release.
    There are a few things that can trip you up, such as: all the
    HTML inside the Javascript area (the
    escape('Some text') portion) cannot have carriage returns;
    and certain characters must be escaped with a backslash (such as
    replacing double quotes with backslashed single quotes). However,
    it's all explained quite well on his site. You can control
    backgrounds, transparencies, images, placement, etc.
    As Peter says, do all your testing in a scrub project before
    going live in the real one.
    Good luck,
    Leon

  • VI Method "Front Panel:Get Image Scaled" Memory Error 17

    Hi all, I've got two almost identical sub vi front panels that I'm dumping to a jpg image for reporting purposes.  One was copied and slightly modified from the other to show a different data set and plot.  The original works just fine, but the second sub vi, when using the "Front Panel:Get Image Scaled" method to pass the image to write the jpg, always returns the following error:
    "Error 17 occurred at Invoke Node in Myprogram
    Possible reason(s):
    LabVIEW:  Not enough memory to manipulate image.
    =============================
    NI-488:  Unrecognized command.
    Method Name: Front Panel:Get Image Scaled
    [Continue] [Stop]  "
    I've stripped the problem section into a simple tiny new that only opens the report and tries to get the image with the same working/non-working result above.  Using the Execution Trace Highlighter, it error is definitely occuring when the Method executes.
    Any ideas?  Thanks.

    Hey cjgpr,
        I haven't been able to dig up much info on this error message.  There's one other discussion forum post that talked about it some, and a KnowledgeBase article on it.  It seems that whatever changes you made to the front panel have caused it to exceed your computer's memory when creating an image.  Try removing items until it works, then see what actually breaks the functionality.
    Brian B
    Field Sales Engineer
    Tennessee/Southern Kentucky
    National Instruments

  • Making Roll over images from photoshop layout

    Hello Everyone,
    I am working on a website and I have sliced my parts of my Photoshop file.
    I have saved as a html with images as well!
    How would I amek a roll over image out of the buttons I made in photoshop and sliced?

    Best thing you can do is delete that HTML file from Photoshop and use the slices and build the code in Dreamweaver.  You will be much better off.
    The simplest solution is to save the 2 states of your button as 2 separate images then click on Insert->Image Objects->Rollover Image.  Then select your before and after image.  Just remember to upload the javascript file Dreamweaver creates during this process or it won't work online.

  • Metadata ? Login before download? Mouse over image? Three questions...

    Three questions:
    1) Can I add metadata to pages made with iWeb? Does it have to be done in an external application (and if so why)?
    2) I would like to propose a PDF document (a catalogue of services) that can be downloaded from my site but only to visitors who have logged in or at least left their identities (I want to know who has downloaded the catalogue and to be able to contact them afterwards).
    3) I want to have a roll-over image which will show a photograph before and after retouching, switching between the two as the mouse cursor goes over the picture. Can I do this in iWeb?
    Any ideas?
    Many thanks!

    2 - as already suggested you can use a form site to create a form to give you the information you need. DYou can add the form to a web page with an HTML Snippet and iFrame code like in this demo page. The code used is also shown. on't know if you can set it up to download the pdf file but you might be able to add a link to the zipped pdf file which would immediately download the file.
    3 - to do the rollover that you want would require javascript and a snippet. Do a search in this forum for "rollover" and you'll a number of topics where it's discussed. Cyclosaurus is the resident expert on javascript.
    OT

Maybe you are looking for

  • Help needed in Service Ticket view version CRM 2007

    Hi, We have a requirement to replace the Service Level Agreements with Location details screen (custom defined) in the Service Ticket View. I did this in 5.0 version,but couldn’t replicate it in the CRM 2007 version. Here is how I proceeded in the ne

  • For Lightroom 4...

    I've been a long time user of Lr, starting with the first beta and I mostly love it. It was only recently I tried Aperture 3, I wrote an indepth review of Lr 3 vs Aperture 3 (and others) here: http://www.twin-pixels.com/raw-processors-review-aperture

  • ICal creates hundreds of events

    Hi. I just created a three day repeating all day event in April. To my horror iCal created not just the event I wanted but hundreds of other, separate events, though all in the same conferences calendar, lasting up to May 2010. Any ideas? I sync this

  • Training for Crystal Reports Server

    Does anyone know of any place that offers training for running CR Server 2008? We are having trouble getting everything to talk to each other and wondered if there was a good place to help. Thanks,

  • What I believe to be a fix for all the problems as of late with the mini.

    Now I have been swarm with the same problems as everyone else with the not registering in itunes so you can download new songs into it. I have tried all the different methods to try and get it to work again but to no avail. I was acut get disgusted w