Search code examples
javaswingwindowawt

Making Java window without JFrame or AWT


First of all, I want you to know that I searched the web for that but couldn't find anything. I remember that I saw a thread on it once but couldn't find it again; it was a long time ago.

I want to know how to make my own window, without JFrame or AWT. Everywhere I am searching just shows me library and pre-made code but I can't learn how it works inside. I want to know how to build a window, without what Java already gave me.

The good thing and the bad thing in Java is that Java makes things easy for the developers, so, that's why I tried C, searched for assembly code and tried to find a way to do this, but all of the approaches used libraries.

That why, I want to know, it is even possible? Don't need all of the windows, just the base of it or even pixels on the screen, but something that will not include using more libraries or made classes that were built for that and everyone using just because this is the only thing they know.

Thanks to everyone that will help me and will answer my question(s) :)


Solution

  • In Java, we are reliant on bindings into the native OS. The reason we have abstract frameworks, like AWT, Swing, JavaFX, SWT is because the process by which this is done is not trivial, especially if you actually want to paint to these surfaces in some meaningful way and is compounded when you consider the different requirements of the available operating systems.

    Depending on what you actually want to achieve, will depend on which way you will go, for example...

    You could...

    Use a JWindow or an undecorated JFrame. This provides you with a available painting surface and a connection into a ready made event queue (message loop).

    These two windows present you with an "empty" rectangle with no decorations. When dealing with these types of windows, you can provide your own decorations directly or via a custom look and feel.

    You could...

    Use a JNI (native) binding directly into the operating system which would allow you to ask the OS to create a window of your own. This means that you become responsible for determining how you are going to paint to the window, how you are going to process messages (events) from the OS that are targeted to your window and all other considerations.

    Take a look at JNA Win32WindowDemo.java or if you really want to get funky, you could also have a look at ...

    as some additional bindings into native graphics library