I need to find a component's exact screen size in pixels when the main JFrame is resized.
I've tried several things and couldn't find an easy way to do it: it probably have missed something obvious.
BBBBB JFRAME BORDER BBB
BZZZZZZZZZZZZZZZZZZZZZB
BAAAAAAAAAAAAAAAAAAAAAB
BCC1................DDB
BCCC................DDB
BCCC................DDB
BCCC................DDB
BCCC................2DB
BEEEEEEEEEEEEEEEEEEEEEB
BBBBBBBBBBBBBBBBBBBBBBB
Resized, it could become this if, say, the user made the main JFrame shorter (vertically) and wider (horizontally):
BBBBBB JFRAME BORDER BBBBBB
BZZZZZZZZZZZZZZZZZZZZZZZZZB
BAAAAAAAAAAAAAAAAAAAAAAAAAB
BCC1....................DDB
BCCC....................2DB
BEEEEEEEEEEEEEEEEEEEEEEEEEB
BBBBBBBBBBBBBBBBBBBBBBBBBBB
What I want is to find the exact size in pixels, on screen, of the rectangle area indicated by dots.
I'm adding a ComponentListener
to get the resizing events, which works fine.
The issue I'm having is that calling getWidth()/getHeight() on a Component does apparently not return the component's screen size but the component's actual size (and you can have, for example, a JPanel wider than the component it is into).
Any hint most welcome.