Is there a JFrame.getBounds equivalent that gets only the actual client area?
Asked Answered
S

2

5

Instead of the whole window complete with close, maxi- and minimize buttons, as well as border?

I'm trying to save a screenshot of the client area...maximizedBounds crashes the app...

Sabadilla answered 29/8, 2011 at 17:6 Comment(0)
I
6

Get the bounds of the content pane instead (i.e. JFrame.getContentPane().getBounds()).

Impermeable answered 29/8, 2011 at 17:13 Comment(3)
that works, but I have to adjust the coordinates of the snapshot, it seems.Sabadilla
I'm using the Robot to create the snapshot, your approach returns the correct dimensions, but x and y coordinates are both zero, I guess because getBounds returns the position relative to the parent, and that's x0 y0 for the panel. This results in robot taking a screenshot of my desktop that covers 0,0,PanelWidth,Panelheight, which only covers a region of my app, which is in the center of my screen.Sabadilla
looks like as for that would be required Frame.getXxx +1Treacle
S
5

This did the trick:

   Point pos = this.getContentPane().getLocationOnScreen();
   Rectangle clientRect = this.getContentPane().getBounds(); 
   clientRect.x = pos.x;
   clientRect.y = pos.y;
Sabadilla answered 29/8, 2011 at 17:31 Comment(1)
+1 For explanation in comment to my answer and for providing this answer for further clarification.Impermeable

© 2022 - 2024 — McMap. All rights reserved.