Getting the position of a component in a container for repainting

This may be a stupid question but, I want to get the position of a custom component as it lays in a JFrame. This is needed for a repaint of the special component. getX() and getY() return the origin of the component as it is painted in paintComponent(). How might this be done without messy parameters to an overridden repaint method?
I need the position so that I can cut out a portion of an underlying background image in the JFrame, so that I can repaint the component's text without clearing away the image or painting over it with a color. If anyone has a better idea, I'm all ears. . .
Thanks.

as a near solution to my problem, I have created the following method to locate the exact origin of the custom component:
     private int[] getAbsolutePosition(Component c)
          int pos[] = {this.getX(), this.getY()};
          int x = 0;
          int y = 0;
          Container parent = c.getParent();
          while (parent != null)
               x = parent.getX();
               pos[0] += x; // append next width
               y = parent.getY();
               pos[1] += y; // append next height
               parent = parent.getParent();
          pos[0] -= x;     // Remove the position of the parent frame
          pos[1] -= y;     // from the totals.
          return pos;
     }The custom component has 3 JPanels, one Container, and a JFrame beneath it. I remove the JFrame positions becuase they would mess things up. Still, the x values it returns are off by a small but noticible amount. Does anyone know what might account for this?

Similar Messages

  • Get the position of the component on GUI ???

    Hi All,
    How can I get the position (x, y) of a component such as JCompoBox on Frame at runtime ?
    Thanks a lot,
    Huy

    To the the location of a JComponent in it's parent... just use the getLocation method on the JComponent.
    If you need that point relative to some other ancestor, I would use SwingUtilities.convertPoint
    Hope this helps,
    Josh Castagno
    http://www.jdc-software.com

  • How to get the position of a tag in XML,when i am using the org.xml.sax

    Hi,
    I am able to parse a xml document.I want to get the position of a tag in the document.So that by keeping that as reference, i can access other tags.Plz help me.I am using org.xml.sax API.

    Hello Friends
    After research , I could also find another way to check the existence of a node .We can even use CHOOSE to check the existence.
    <xsl:choose>
          <xsl:when test="(/mynode)">
              your action if the mynode is found
          </xsl:when>
          <xsl:otherwise>
                    action if mynode is not found
          </xsl:otherwise>
    </xsl:choose>
    Thanks.
    Wishes
    Richa

  • How to get the position of a selected cell in a table ?

    Hi,
    How can I get the position of a selected cell in a table or in a list multicolumn cmd ?
    Thanks.

    Invoke node >>> point to Row Column
    Ben
    Message Edited by Ben on 07-19-2007 03:14 PM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    Point_To_Row_Column.PNG ‏22 KB

  • Is it possible to get the position of a charcter from a string ?

    Hi !
    Is it possible to get the position of a charcter from a string ?
    Example:
    @VAR contains the following text "ABCDEFGHIJKLM"
    I'am seaching for FGH, it start on pos. 6 en ends on pos 8.
    How can I get these numbers 6 and 8 ?
    So, I can use them in the MID(text,start,len) function.
    Thanks!

    Hi Sooraj,
    I'll explain more in detail:
    From a web-service I get a variable called @Spec.
    This variable contains the following:
    "MOTORTYPE[CR]D-QW1234[LF]PART[CR]1234-FRD-X[LF]"
    or
    "MOTORTYPE[CR]ABC[LF]PART[CR]E-435[LF]"
    I need the values behind MOTORTYPE[CR] and behind PART[CR]
    But you’ll see that the positions of these values are different each time.
    If there is a way to get the (start) position of "MOTORTYPE[CR]" or "PART[CR]" and the (end) position of the first "[LF]" behind that,
    then I could use the MID() function to get the correct values.
    The values will be displayed in a table view (between other fields).
    An ABAP-call/function won’t work . . . how should I invoke this within a table column/field object ? (system action ?)

  • HELP!! How to get the position of active windows in the desktop

    How to get the position of active windows in the desktop

    You mean, active windows other than the program you're running, or windows the program puts there? And a real desktop (like where MyComputer is), or a desktop pane?

  • How to get the position of the stem in control valve using slider control in the front panel

    I have created a calibration program for a control valve. Signal (4-20mA) is generated from labview using slider contorl which is given to the valve via DAQ(module 9265) and again the feedback signal from the valve is acquired using DAQ(module 9203).. . There is an input ISO/ISC(Increasing signal to open/ Increasing signal to close) in the front panel.
    ISO would set the output to increase from (4-20)mA further opening the valve
    ISC would set the output to increase from (4-20)mA further closing the valve
    I have doubt, how can i get the position of a stem

    Ravens Fan wrote:
    If the position of the stem is being sent to the PC through a 4-20 mA signal into your DAQ 9203 module, then you just need to do an analog input read in order to get the signal.
    When reading this post, that is what came to mind...  So let's see if both RavensFan & I are trying to understand the same thing...  Are you saying that the position of the stem is linear (or scaled) to the amount of current sent to it?  Meaning a 4mA signal would move it a certain distance, and 10mA would move another given / known distance?  Or are you saying that it is calibrated so that a 20mA signal for a certain duration (ms) would move it a given distance? So the scale would be time and not current unless a lookup table is used to adjust the time duration based on the current being drawn...
    It's just that I am not familiar with solenoid / drive devices that related to current..  To voltage, yes.  To time, yes..  To current, I'm simply saying that I am not familiar with that.  Can you tell us more about this stem (mfg / model designation)?

  • How can i get the position of my object

    HI,ALL! i get a queation now. when i picking some transfromgroup,and move it.(use picktranslatebehavior),i want to get the position of the transformgroup after it has been moved.so how can i get it?!Apology for my bad english .thanks!:)

    Check out:
    http://forum.java.sun.com/thread.jspa?threadID=633485&tstart=15

  • How can I get the position stream for a composition?

    I am writing an AEGP plugin for AfterFx and I need to get the position stream for a composition. I have based my plugin on ProjDumper.
    Can anyone help?

    Hi Shachar,
    Many thanks, that goes some way to explain it.
    However I am creating a composition adding text layers to it and animating the positions of the individual text layers. Then I create a second composition and include the first as a nested composition and I animate the position of the first composition within the second composition.
    When I run my plugin I only see the animations I added to the individual text layers, they are not combined with the overall animation attached to the first compisition within the second composition.  The animation data for the first composition must be stored somewhere. Do you know where ?
    I have been looking at source items and markers neither seem to provide the information I am interested in. Any clues would be very helpful.
    Thanks in advance.

  • How can I get the position assigned to the user in CRM .

    Hi all ,
    How can we get the positions to which a  user is assigned as a holder in CRM .
    Thanks ,
    Naval bhatt .

    Hi,
         Use the PPM toolkit class CL_CRM_PPM_UM_TOOLKIT. You can use the method You can use the method GET_ASSIGNMENTS_OF_USER which returns positions held by an user(user name).  You may also find the method GET_POSITION_OF_USER useful. It accepts username and the organization ID and will return the positions held by the user under that organization.
      This class always uses the current plan (01). If you want otherwise, you can use the FM RH_STRUC_GET. As to how this FM should be used, look inside the above said methods.
    Regards,
    Arun Prakash
    Edited by: Arun Prakash Karuppanan on May 11, 2010 11:40 AM

  • To get the position of the characters in the string in sql

    hi all,
    I need to get the position of the characters in the sql , the string like this '10101110111010111' , is it possible to get the answer like this
    pos char
    1 1
    2 0
    3 1
    4 0
    and so on .
    Thanks in advance .

    select level pos,substr(:your_string,level,1) "char"
      from dual
    connect by level <= length(:your_string)Regards
    Etbin
    Edited by: Etbin on 24.9.2011 8:46
    put char between double quotes http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/ap_keywd001.htm#BABCJAEB

  • When installing CS3 Design Premium it instals Version Cue server and shared components, but I get the message "Errors: 6 component (s)" and dose not install, Photoshop, Flash, Illustrator, Indesign or Creative Suite Premium

    When installing CS3 Design Premium it instals Version Cue server and shared components, but I get the message "Errors: 6 component (s)" and dose not install, Photoshop, Flash, Illustrator, Indesign or Creative Suite Premium

    Thank you Bturko in the future only migrate/copy/transfer your documents and settings.  Adobe applications especially are not designed to be transferred from one computer to another.  It is possible to recover however.  I would recommend the following steps:
    Run the uninstaller located in Applications/Utilities/Adobe Installers
    Run the CC Cleaner Tool to ensure complete removal - Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6 - http://helpx.adobe.com/creative-suite/kb/cs5-cleaner-tool-installation-problems.html.
    If you need to download a fresh copy of the installation files they can be downloaded at Download CS3 products.
    Run the installer and reinstall Creative Suite 3.

  • How to fix the position of different component?

    Hay all,
    Can anybody tell how to fix the position of any component so that they cant be moved from there initial positiion
    Regards,
    Sharad Agarwal

    Set layout to null and set bounds of the component to whatever you like.

  • How do I get The ipad locked to run only one application for customers (perhaps a webapp)

    how do I get The ipad locked to run only one application for customers (just one web app, or video- instructions, or just safari). What I really want is that my customers to only use one app that has all my services. It is an interactive app so I would not like them to go surfing elsewhere while they are in my store.
    Is it possible to do this on the iPad ?

    Try this:
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    checkbox - clusters_MOD.vi ‏23 KB

  • Hello Vivek here, i was trying to download apps from itunes and i could get the error message as itunes currently not available for past 2 days

    Hello Vivek here, i was trying to download apps from itunes and i could get the error message as itunes currently not available for past 2 days, is there any problem ideally or, please leave a reply
    <Email Edited By Host>

    Hi vivekanandanganesan,
    Thanks for using Apple Support Communities.  This article has some steps you can try if you are unable to connect to the iTunes Store:
    Can't connect to the iTunes Store
    http://support.apple.com/kb/ts1368
    Cheers,
    - Ari

Maybe you are looking for

  • Nook not recognized by Windows 7 computer or ADE

    ADE installed, doesn't recognize Nook, nor does Windows 7 computer.  Any ideas?

  • File Sharing Permissions to Documents Without Having to Assign Each?

    Not sure where else to ask this. Background - work environment. Small 3 person office. Airport network. All computers Duo2Core with 10.5.1. On my iMac - I have this configuration: Home>Public>Shared>Clients> Abel thru Zulu - (separate folders for eac

  • Is there a maximum size per iMovie event in iMovie '09?

    I merged two iMovie events into one (on an external hard drive), backed it up on a second external hard drive, and found that all the clips in that event on both the original ext drive and the backup drive had lost the sound. The clips played in iMov

  • Small format videos

    i have 320 x 240 videos that i want to edit in final cut express HD. in my old FCP i could just create a setup for this frame size, but in HD i just cannot see how to get my project and sequence to be the right size. i thought maybe i could capture s

  • Transferring cellphone photos to my computer

    What cord do I use to transfer Verison cellphone photos onto my computer.  I have used some usb cords but nothing works.