How do I draw that semi-transparent rectangle on the screen?
That cannot be a JFrame
because JFrames have the usual close, minimize, maximize options in top right.
if it is indeed a swing competent, How is it drawn in thin air? Without inserting it in a JFrame
whatsoever?
Please tell me what it is and how I can implement it...
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
The immediate idea that comes to mind is to use
java.awt.Robot
to capture a screen shot, paint that to frameless window. From there you can simply draw a rectangle on itUpdated with example
... Took some time ...
Update with SnipIt Example
Some people have suggested using a transparent window laid over the top of the screen, this actually won't work, as transparent windows don't actually respond to mouse clicks UNLESS they have something to be painted on them that will allow the mouse event to be trapped.
It's also been suggested that you use a Window as the selection mechanism, this is a valid answer, however, I would (personally) find that to be an unsuitable solution, as you want the user to simply click and drag the selection rectangle (IMHO).
Another approach is use something like SnipIt.
Update Multi Monitor Support to the Example Answer from @MadProgrammer.
Without
ExtendedState(JFrame.MAXIMIZED_BOTH)
andpack()
You could use a transparent, undecorated frame in order to create a basic border.
The frame may also need to be
setOpaque
, or the panel size may need to be handled, but this is the general idea of it.