Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Draw to screen directly / transparent fullscreen overlay: Which framework to use?  RSS feed

 
Joseph Bloesinski
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I want to write a "software laser pointer" - that is, an application that shows a red dot on top of any running applications which moves around based on touchscreen input on a bluetooth-connected smartphone. My current approach (for the red dot overlay part) is to use an undecorated fullscreen JavaFX stage with setAlwaysOnTop(true), but I think there could be better solutions, I'm also having trouble getting that stage to repaint when another application is focused.
Basically what I'm looking for is a way to draw on top of everything without creating a fullscreen window, because mouse and keyboard events should still be received by whichever application has the focus. Since I'm not very skilled with C languages, I'd like to use pure Java as far as possible (one platform-independent piece of code would be nice, too). Are there any frameworks suited for this? I started looking into fullscreen exclusive mode stuff, but the examples I found always used a JFrame, which would then consume all input events (I think?)...

Thanks in advance,
Joe
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Does Java FX run on smart phones?

I want to write a "software laser pointer" - that is, an application that shows a red dot on top of any running applications which moves around based on touchscreen input on a bluetooth-connected smartphone

I do not think this is possible with the approach you have in mind. Effectively what you are trying to do, is superimpose your app on top of some other app. There might be some 'native' approach on smart phone, but I doubt, it is possible with JavaFx or Swing or any other 'Java' framework.
 
Joseph Bloesinski
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answer!

The laser pointer part is a program running on a pc, maybe I shouldn't have used the word application in the same context as smartphone, sorry.
So the whole setup right now is as follows:
- A bluetooth client app running on an Android smartphone, which converts gestures to a series of coordinates sent to...
- a bluetooth "server" program running on a Windows 10 laptop (where the JavaFX stuff takes place at the moment)

I have two more specific questions regarding my problem:
1.) Is there a way to make a fullscreen exclusive mode application with for example an undecorated Swing JFrame transparent for mouse events?
2.) Is it maybe a better idea to have a tiny undecorated transparent window just big enough to display the laser pointer dot and move that whole window (instead of moving the dot inside a transparent fullscreen window) ?

Thanks again,
Joe
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah. Now I understand better.

Don't know about JavaFX, but in swing you can use the glass pane. Check out https://docs.oracle.com/javase/tutorial/uiswing/components/rootpane.html
Another (recent, JDK 7 option) is JLayout. More on it here http://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html

PS. I haven't worked on JavaFX but I think it is possible to use Swing components in JavaFX
 
Joseph Bloesinski
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again for your time, the problem is resolved.

I stumbled upon this stackoverflow answer which does what I need.
The solution for me was to use a transparent fullscreen-sized undecorated always-on-top JFrame with a JPanel content pane using an active rendering loop to call the content pane's overridden paintComponent() via contentPane.repaint().
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!