Getting absolute position of component

hi
i want to take a screenshot of the content of a specific JFrame in my ui
what the code below does is take a screenshot of my screen starting at its (0, 0) coordinates
but not starting at the so called (0, 0) of the JFrame
     Robot robot = new Robot();
     Dimension dimension = getJFrame().getSize();
     Rectangle rectangle = new Rectangle(dimension);
     BufferedImage screenShot = robot.createScreenCapture(new Rectangle(rectangle));how can i calculate the offset to the JFrame ?
i already tried all kinds of things
and didn't find any reference online
thanks

You use this on the JFrame:
//from the API
getLocationOnScreen
public Point getLocationOnScreen()Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space.
Returns:
an instance of Point representing the top-left corner of the component's bounds in the coordinate space of the screen
Throws:
IllegalComponentStateException - if the component is not showing on the screen
See Also:
setLocation(int, int), getLocation()Then use your component location as an offset from the JFrame location.

Similar Messages

  • Absolute Position of Component

    hi!
    i'm currently creating a formvalidator.
    is a field-validation failed, the validator paints a small red dot on the glasspane over the lower left corner of the field/component.
    my problem now is the following:
    is the component i want to validate in a container, the getLocation()-method of the component does not give me the absolute position of the component... so my red dot is painted on the false position.
    does anybody know how i could get the absolute position of my component? (absolute; relative to my topcontainter, the JFrame or the JDialog)
    thx a lot!
    greetz
    swissManu

    Hi,
    have a look here :
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/SwingUtilities.html#convertPoint(java.awt.Component,%20int,%20int,%20java.awt.Component)
    it should permit you converting coordinates relatively to anything ;-)
    Nico

  • Get absolute position of mouse.

    Hi,
    I want to move mouse by specified offset. I'd like to use method of Robot class, but it need absolute coordinates on the screen.
    So I need get absolute coordinates of mouse to count new coordinates from given offset.
    Know somebody how I can get it ?
    Thanks,
    Vasek.

    There are two static methods in the class SwingUtilities: convertPointFromScreen() and
    convertPointToScreen().
    Mitch Goldstein
    Author, Hardcore JFC (Cambridge Univ Press)
    [email protected]

  • How do i add a Scroll Bar to a  JList Component using absolute positioning?

    I've got a applet whose content pane is set to null. I've create a jlist component on this applet and using absolute positioning set the bounds at
    ListBox1.setBounds(380,10, 500, 500);.
    My problem is creating add a scroll bar to the list box.
    JScrollPane scrollPane = new JScrollPane(ListBox1);
    C.add(scrollPane);
    The above code is what i use and when i run this applet i don't see the list box at all. How do i add a scrollbar to this list box or JList component. Please help.

    You need to setBounds() on the JScrollPane, not the JList.
    The JScrollPane is the component that is being added to the panel.

  • How to get the caret position of component embedded in JTextPane?

    Hi great java developers ;-)
    I want to get the caret position of component which is embedded in StyledDocument / JTextPane.
    How has it to be done?
    Thank you very much!!!

    The Document doesn't know which textPane it belongs to. (It could even be shared by mulitple textPanes).
    You get the caret position of a any text component by using:
    textComponent.getCaretPosition();

  • 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

  • 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?

  • Find browser or applets absolute position

    Hi,
    I am designing an applet where I open a number of small pop up windows at the beginning of the applet. Users of this system have two monitors, thus I need to determine where they have positioned the browser so that the windows will open above the browser. At the time the windows open there is nothing else on the screen so getLocation doesn't work.
    If I can determine the absolute position of the applet this would also do.
    All help would be greatly appreciated.

    I use the following to get a reference to a Frame which I pass to a JDialog constructor to ensure that the Dialog is always centred over an Applet no matter where the Applet is positioned on screen. Maybe you can adapt it for your needs.
    public Frame getDialogFrame()
              /* creates and positions a Frame used by dialogs
              *  to ensure that dialog is modal and centred over the Applet
              Object parent = this.getParent();
              while(!(parent instanceof Frame))
        parent=((Component)parent).getParent();
              Frame dialogFrame = (Frame) parent;
              Point p = this.getLocationOnScreen();
              dialogFrame.setLocation(p.x, p.y);
              return dialogFrame;
         }

  • Box model/none absolute positioning with flash

    In recent years none-absolute positioning (or box model positioning) has become the norm with HTML/CSS
    this is uselfull for dynamic functions which appear on an event (such as an object which appears when a button is clicked on or a error message that appears when a form box is given invalid input because it automatically inserts itself it the right place.)
    One very important example of this is when you have a form which automatically produces an error message and the error message appears bellow the input area which caused it and the rest of the page is pushed down.
    With none absolute positioning the developer does not need to worry about this.
    But if the objects are given absolute position then it becomes a massive problem, the developer has to go about giving the objects differetn positions dependant on if dynamic objects appear or not
    potentially the developer has to consider all possible variables, and code if statements which determine the position of all static objects for all possible variables which dynamic objects could take.
    so does flash have a "none absolute positioning" solution to this problem.

    Before you get all happy and pleased with yourself, APDivs or Layers seldom work well as a primary layout method. Here are some reasons why:
    http://apptools.com/examples/pagelayout101.php
    You're much better off using default CSS positioning (which is no positioning at all) along with CSS margins, padding and floats.  If you don't believe me, check your page in non-IE browsers with increased/decreased text-sizes (zoom, text only).
    From  Tables to CSS Web Design Part 1 -
    http://www.adobe.com/devnet/dreamweaver/articles/table_to_css_pt1.html
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb
    http://alt-web.blogspot.com

  • Rendering bug with absolutely positioned button tags

    I'm using Firefox 10.0.1 and I've found a bug regarding button elements that are absolutely positioned. The problem is setting both the right and left CSS attributes does not affect the width of the button as it should.
    Here is some example code to show what I mean (the forum is mangling the html, hopefully you can get the gist of it):<br />
    <br />
    <pre><nowiki><html>
    <body>
    <div style="width: 500px; position: relative;">
    <button style="position: absolute; left: 0; right: 0;">Test</button>
    </div>
    </body>
    </html></nowiki></pre>
    In all other browsers the button will be 500px wide. In Firefox, it will fit to the text.

    Why don't you give that button a width:100% if you want it to take the full width of that DIV container?

  • Bayside Beat Tutorial - Part 4 - Absolute positioning

    I am stuck on the Absolute positioning section. My image is supposed to be spread out across the screen and the text is supposed to be at 36% as a layer on top of the image. Here are the instructions:
    To keep related styles together, select #wrapper in the Selectors pane, and click the plus button to create a new selector called #hero after it.
    In the Layout category, set the position property to relative.
    With #hero still selected in the Selectors pane, create a new selector called #hero article to style the <article>element nested inside the hero <div>.
    In the Layout category, set the width property to 36%, and left and right padding to 10px.
    Set the position property to absolute.
    The moment I set steps 4 & 5, I get the following layout:
    It should look like this:

    Looking at your screenshot, it looks as though you have wrapped the <article> around the hero <div> in the underlying HTML. The problem isn't with your CSS, but the HTML structure.
    Compare your HTML file with the version in the completed folder.

  • How to force absolute positioning

    Hi
    I am trying to force absolute positioning when I export to Dreramweaver.
    How can I do this.  Ive been trying to overlap my images and hence slices when I export but I never get the warning up about absolute positioning.
    Any ideas
    Thanks

    Create the images in Fireworks and export them to the images folder of the site you have properly defined in Dreamweaver. Build the pages with the images in Dreamweaver. Fireworks can only export images "overlapping" on states which are animations, or buttons, or image swaps.

  • Looking for confirmation regarding absolute positioning...

    Absolutely-positioned elements *never* interrupt the flow,
    regardless of
    what that element is.
    As such, scrollbars completely ignore said elements at *all*
    times, as if
    they weren't there at all.
    Are both those statements considered pretty much factual?

    > Would there be any way *at all* to place a div outside
    the viewport
    > WITHOUT generating a scrollbar?
    Yes - place it to the left of the left margin, or above the
    top margin. 8)
    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
    ==================
    "Mike" <[email protected]> wrote in message
    news:g8rohn$8go$[email protected]..
    > "Murray *ACE*" <[email protected]>
    wrote in message
    > news:g8rgne$rdc$[email protected]..
    >>> Absolutely-positioned elements *never* interrupt
    the flow, regardless of
    >>> what that element is.
    >>
    >> Absolutely positioned elements are REMOVED from the
    flow, so yes, they
    >> can never affect anything that is located by the
    normal flow.
    >>
    >>> As such, scrollbars completely ignore said
    elements at *all* times, as
    >>> if they weren't there at all.
    >>
    >> Curiously not. Place an absolutely positioned
    element 2000px to the
    >> right of the page's right margin and you'll get a
    horizontal scrollbar.
    >
    > How strange.
    >
    > Would there be any way *at all* to place a div outside
    the viewport
    > WITHOUT generating a scrollbar?
    >

  • Absolute Position

    What does 'absolute' for the position attribute of a component mean?
    And what others possible values?
    Regards,
    Marlos Rodrigues.

    It's a standard CSS2 property.
    http://www.w3.org/TR/CSS21/visuren.html#absolute-positioning
    -- Tor
    http://blogs.sun.com/tor

  • Getting absolute file name using af:inputFile

    Hi all,
    Can you help me how to get absolute file name (e.g., C:\Documents\file.txt) using <af:inputFile> component or using any another JSF component.
    Thanks in advance :)))

    we can't get absolute path using inputFile, we can get only the file name. as per my knowledge we don't have any other component also.
    i have one of my requirement i need to read file from specified folder, so i have hard coded my folder name in my managed bean.

Maybe you are looking for

  • Unprotect OIM 9.1 page in OAM 11g?

    I have configured 10g webgate with OAM 11g and everything seems to work great. I have a requirement to unprotect /xlWebApp/forgetPassword.do to allow password reset without challenge. I get the below error in OIM when trying to access the page. Looks

  • When away/offline status will be solved

    Hello! I would like to appeal on Microsoft seriousness and ask for serious answers! When this problem will be solved? There are hundreds posts in different forums here and no body from Microsoft answering. Problems with statuses persists about one ye

  • How do I get Photoshop Elements12 to recognize my printer/scanner?

    I have Photoshop Elements6 and just upgraded to 12... but 12 doesn't 'see' my scanner, the import option is grayed out... I just downloaded new drivers for my printer, but that didn't seem to help.    Anyway, I can get my money back for this worthles

  • Not Using All CPUs

    Does anyone know why Premiere Pro CS6 (Windows) is only using 4 CPUs when I have 24 on my Mac Pro? I am running Windows 7 Professional on Bootcamp. I have 48GB of RAM. I am importing JPEGs stills and creating a sequence but it is moving very slow. Th

  • MX922 not seen as TWAIN scanner

    I received a Canoscan 5600F for Christmas with which I intend to scan 35mm slides and negatives.  Works great but it appears its drivers have hijacked my MX922 scanning capability.  I can only access the scanning function through quick menu vice dire