I want to make an application which will have the following:
a jframe (or frame, or whatever) with some java style menus (Jmenu) on the side, and on the other side of the jframe, a OpenGL canvas (which only occupies part of the jframe) and let them integrate together.
meaning, for example, I want to change a slide, and it will change the view of the opengl.
Is it even possible to embed an OpenGL inside a Jframe?
Also, a recomandation for an opengl library that would support such thing. I played a bit with JOGL, but also saw that there are other open-source, and also LWGL and stuff
EDIT:
Added an image from a project made with JOGL which is exactly what I'm after.
A canvas of JOGL inside a Java GUI
for hight Graphics performance is required to use AWT Component exclusively,
I'd suggesting not mixing AWT with Swing
maybe JOGL could be right way, maybe not
Related
A while ago I wrote an application in Java using Swing for the GUI development. As I want to learn more about JavaFX I'm trying to convert it but I get stuck on one piece of my application I can't seem to find the right equivalent for in JavaFX. In Swing I was able to make a JPanel, create an image, and then rescale the image based on the size of the JPanel using the component events on the panel. Then I'd draw stuff on the image and draw that on the graphics of the JPanel. Also I'd use mouse events on the JPanel to implement zooming and panning on the underlying image.
I'm not sure whether this was good practise in the first place, but it enabled me to draw anything, from pixels to lines to circles to images, on the JPanel, essentially creating sort of a rendered viewport for my application.
What would be the best way to go about this in JavaFX? I've looked at tons of tutorials and youtube videos, but they all seem to focus just on normal GUI controls like buttons, and when I look at game dev for example they make a lot of use of standard JavaFX Nodes to quickly generate moving entities in their scene. I just need sort of a canvas to render stuff on as I please, but if I add something like a default Canvas or Region in the Scene Builder for my FXML file I don't know how to start drawing on that. I'm completely lost in the jungle of tutorials and documentation on the internet.
Does anyone know of any good resource for this kind of application cause I just don't know where to start.
While java programs are platform independent, the JVM itself is platform dependent. I am interested in knowing how Java draws the application GUI (buttons and text) on the screen.
Under Windows, control objects such as buttons are usually created using a window(from user32.dll) or a rectangular region(from gdi32.dll), text is drawn later to the corresponding window/region handle using the provided user32/gdi32 text draw functions.
I tried running a simple two button Java gui application using swing and hooking the majority of create region/window and text draw functions from gdi32.dll and user32.dll, but so far, it seems the Java program is just using these native dlls for drawing the main window frame only.
Does Java.exe uses some other dlls to draw buttons and other controls on the screen ? And if so, why is this case when there are already available native dlls for drawing ?
On Windows Java2D uses Direct3D renderer to draw primitives by default. You may disable it by specifying -Dsun.java2d.d3d=false. In this case GDI renderer will be used.
Add -Dsun.java2d.trace=log,verbose option to trace which Java2D primitives are called in your Swing application.
From the Wikipedia Article:
Unlike AWT components, Swing components are not implemented by platform-specific code. Instead, they are written entirely in Java and therefore are platform-independent. The term "lightweight" is used to describe such an element.
JFrame is Extending Frame. Then, How JFrame is lightweight but Frame is heavyweight?
I red this article but still i didn't get how JFrame achieves its lightweight property?
I got from here that JFrame is heavyweight but other Components starts with J* are lightweight. How other Swing components achieves this. I need bit of technical details.
Technically it's not. Both are heavy weight components, but because JFrame has been setup to support the JRootPane, which contains the content pane (and possibly) the glass pane (as well as the JMenuBar), it is consider "light weight", because it's been deliberately configured to support light weight components
Essentially JFrame and JWindow have been modified as light weight containers that support light weight components
it is still a heavyweight component because it(JFrame) inherits from the Frame.And it is not belong to the JComponents which is lightweight components.
Heavyweight means each Java component has a native peer associated with it. A native peer is an OS-specific component... AWT is heavyweight, so if you create a AWT Button, on the Windows platform an MFC button is created, on *nix a Motif button is created, etc.
Lightweight means that there is not a native peer associated with the java component. This is done by having only the top-level component be heavyweight and all the lightweight components are drawn on to it. Swing is lightweight.
Of course, AWT and Swing are specific to standard Java (J2SE). Under J2ME it depends on what sort of device you are using. If you are using a more powerful device, like the Sharp Zaurus, then you have AWT and functionality pretty close to J2SE levels. If you have something like a Java-Enabled cell phone, you don't have all the capabilites that you need for a fully featured GUI, so there are special libraries used for making these applications. You'd need to look at the APIs provided by the device manufacturer most probably.
JFrames are heavyweight, since it's impossible to create a task-view-level window in most OS without creating a "heavy" AWT window. Lightweight components can replace internal widgets with java-based stuff that doesn't require JNI calls, but windows are the special case. JFrame does let you do custom renders, though. Also, if you're using other lightweight stuff, then I suggest using JFrame as well since it makes the rendering more efficient overall than mixing light and heavy components.
It is still a heavyweight component because it(JFrame) inherits from the Frame. And it is not belong to the JComponents which is lightweight components.
This question might not seem very technical but, out of curiosity,I want to know that:
How does bare/raw Swing code written by me, turn into a wonderful graphical application?
For example:
Like when we make a JFrame visible, or when we place a JButton on it. Who makes it happen? OS or Java or JVM.
Who makes the colors come up?
What is the process going on behind the scenes?
I ask this maybe because its the first time in my life that I made a RealWorld graphical application and these questions popped up in my mind!
Thanks in advance!
In Swing, all the GUI components are written entirely in Java and are rendered using Java. For example, JButtons would be drawn by Java and not by any internal OS stuff. Thus, Swing components are called "light-weight components" because they are managed and rendered by Java instead of by the OS (or any native widget toolkit).
Note that Java also has a toolkit called AWT. Swing is based on nested and inherited methods from AWT, except that it creates native widgets using the OS.
So at some point, Swing will have to create a window on the screen and draw on it. The magic that actually creates the window is handled by AWT. Notice that JFrame extends from java.awt.Frame which means that although JFrame may be rendered mostly by Java, it is backed by a heavy-weight native OS window.
In short, there's an AWT toolkit, which is the layer that does all the window management and drawing. It is calling native platform specific code inside the JVM. It is also responsible for java2d drawing. It can use accelerated directx or opengl pipelines.
Swing is developed on top of it. Swing actually draws every button and every object with plain java code. The drawing is handled to a current look and feels that decide how to draw components. So you can override their paint methods, and add some extra things without any problems.
Metal and Nimus LaF are 100% java2d drawn, so inside of them you will find things like drawRectangle and drawLine to draw components. Native look and feels, like windows, gtk, access current operating systems theme to draw something that looks similar to native widgets. That is why they do not always look like native applications.
There are also other gui toolkits for java, like SWT, used, for example, in Eclipse. What it is doing, is getting the window from the AWT, and then putting 100% native widgets on it. It is much better integrated with the OS, looks better, works faster, uses less memory. But with it, you'd have to distribute your application with os specific native libraries and it is less customizable, compared to Swing.
I don't know all the details, but the actual graphics are displayed/rendered via the swing/awt packages through the JVM itself.
What I have is an Application that uses swing components (jpanel, jbutton, jlabel, etc), however I have to use an old PDF viewer (upgrade is not an option) that is based on java.awt.Applet (com.adobe.acrobat.Viewer). The problem comes when I am trying to display it, it draws properly however since this PDF viewer is inside a JScrollPane, it draws over all of the swing components (over the scroll bars and the menu).
Does anyone know how to make the PDF viewer act nicely and not to draw over other components.
Any suggestions are appriciated
You might look at Mixing heavy and light components, which describes some new support for this. I understand "upgrade is not an option", but the discussion may yield some insight.