I would like to create a window such that there is no "black background" area, but instead you see through to any other windows that are open, etc.
That is, render the scene and only the scene, leaving no frame and no background area.
I've read about a method that involves rendering to a hidden OpenGL window and buffering it in memory, creating a transparent layered window, and copying from memory to the transparent window.
Obviously this is very cpu/memory intensive, so I was wondering if there was any better ways of doing it, within Java and LWJGL?
This is something that can only be accomplished with platform-specific code.
This thread provides an interesting discussion on the subject. This post shares C code that accomplish this effect on Windows, and this post on Linux.
This is OS specific, since the "OS/window manager/not-you-department" owns the other windows.
On Windows, OpenGL cannot participate in this sort of compositing. Other OS's might allow it.
Related
On previous windows systems (and till some point also in Win10) any java swing app have a 1:1 pixel matching with display.
Now when I run the app with JFrame size 1920x1080 on 1920x1080 monitor, it looks like it is about 2/3 of the screen size. It looks like all the application GUI is squized (by downscaling) to fit into 2/3 of the display reslution. This makes everything looks awful.
Now any swing app is scaled down, and the pixels aren't anymore 1:1, this makes the cleartype text look awful, as well as other parts of the GUI, in many cases this render the GUI too small to be usable.
I need to run this app on clients computers, the GUI needs to be appealing, it would be best if I could do it without the need to manually change something in their operating systems.
How could I fix it?
Is there a way to tell the javaVM|win10 to not scale a particular java application?
I know in java-fx to make the window transparent, you need to set the stage style as stage.initStyle(StageStyle.TRANSPARENT);. However this will also remove any stage decorations so this does not solve my problem.
The reason I need this is because my application will need to use stage.setAlwaysOnTop(); at certain points, but this feature is not well supported on the target system (centOS). The application also requires stage.setIconnified();, but this does not work if the stage is undecorated.
Any suggestions will be appreciated.
Thanks
The short answer would be "no, you can't" ... because the minimize/maximize/close buttons are part of the decoration. No decoration - no buttons. It would be a contradiction in itself.
If you need the functionality of those buttons, you would have to create your own buttons as a part of your UI and emulate the behaviour of the decoration buttons. That's what many apps do that come with no default decoration.
Anyway, if you want to manipulate the window behaviour in this way (stay-on-top/iconify, etc.) you always need to take the underlying operating system into account. Any apps (not only Java apps) are only allowed to interfere with window management as far as the OS windowing system allows them to do so.
For example, in various MS Windows versions, the OS behaviour changed several times at this point.
I need to do a loading window in java like this:
I tried with the jframe but I can't figure it out, I can't remove the close button, my jframe should look like a jpanel before that program begin, somebody know how to do this.
You Could...
Use Java's inbuild splash screen support. This is good as it gets loaded relatively earlier in the process by the JVM itself, so it comes up reasonably quick.
The major drawback (in my opinion) is it can be troublesome to get right as it doesn't follow the standard painting process that most developers are use to and you are going to have to paint it all yourself, there's no component support
How do I use SplashScreen without throwing a NullPointerException?
How to Undo the splash screen painting in java
Splash Screen Progress bar not drawing
You Could...
Create a JWindow. This is a frameless window, which won't appear on the taskbar (at least for some OSs).
You gain complete control over what and how things get displayed, as it's like dealing with any other window.
The only problem is that it won't become available for you to load until the JVM has completed loading your application. If the JVM needs to download resources over the network, for example, this could produce an undesirable delay
For example
Splashscreen in Java
SplashScreen java change alpha
Why won't this draw the image?
You Could...
Use an undecorated frame. This is pretty much the same as the JWindow option, except that a taskbar icon will be displayed, but on some OSs, this can't be completely helped.
See Frame#setUndecorated for more details
Final thoughts
Swing is not thread safe. So if you're displaying a splash screen, this means you should be ensuring that whatever actions you are taking are done off the Event Dispatching Thread, possibly through the use of SwingWorker
Is it possible to simply paint() (or use some other function) to the screen in Java? As in draw over everything else on some coordinates of the screen itself, not inside some window.
If not, is it possible to make an invisible window that takes up the entire screen and use its glass pane to do it? Would complications arise from doing this? (Such as not being able to click on other applications)
Are there any other ways?
Thanks.
Edit: I'm not trying to do full screen with this, by the way.
When you paint() in Java, you're painting only within the confines of the size and location of what is being paint()ed.
If you're looking to do full screen stuff, there are tutorials for that:
http://download.oracle.com/javase/tutorial/extra/fullscreen/index.html
In theory, you can create an transparent undecorated maximized JFrame. This will allow you to "paint" over the desktop. Problems are obvious: if an application stays behind this window, it will not receive any mouse events.
Months ago, I made an evil cheat to draw directly on Windows Explorer's Desktop: mixing some .NET coding with JNI and Sun's internal classes - that's surreal, but works.
I've just started making my first GUI application in Java and I decided to use the NetBeans IDE to do it. I think its working fine so far, except for one problem; it seems to be slow updating the content of a window.
Even in very simple windows with few controls I find that when - for example - closing or resizing a window, I get the normal window border working properly but the inside is completely see through for a second.
It's not the biggest deal in the world, I just find it mildly annoying.
EDIT: I've tried the HelloWorldSwing from the official Java tutorial but I have the same issue, only now, when resizing, instead of being transparent, the new area of the window is black until the contents updates.
You should ensure that all of your GUI updates are performed in the Event Dispatch Thread, and that any other long running tasks are performed in worker threads. If you have long running tasks running in the EDT, your GUI will feel sluggish. Take a look at this tutorial for concepts on Swing Threading.
In the absence of any technical problems with your app, this could simply be JVM warmup effects. Do updates speed up if you resize the window a few times?
This could be a Java2D hardware accelleration issue. Is your 3D graphics card driver fully updated?