I've seen in many threads it's not recommended to mix awt and swing components. However I've seen examples in which they add the Canvas to a JFrame (No other swing components are involved). Canvas is an awt component and JFrame is a swing component, so is it ok to do so? and if not, how exactly to use the Canvas?
You could get some unusual display problems with older JDKs, but mixing swing and AWT is fine nowadays. See this article: http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html
I've written a game which used swing components for most of the UI/controls but a canvas for drawing the main game area (see https://github.com/qwerky/Towers/blob/master/src/main/java/lineup/ui/UI.java). It worked fine with no problems.
Related
Is it possible to add Swing components in JME3 canvas? If it is possible please share the logic.
I was able to achieve the other way round where I was able to integrate JME3 canvas in Swing.
No, you can't add Swing components to the JME3 canvas.
I have written a RCP platform (swing components) that displays a bar Graph drawn in processing. When I manually resize the frame, flickering occurs. I would like to find out how to keep this from happening.
Processing and Swing don’t mix well. Have a look at the discussions on the Processing Forum.
I have a swing gui which has proper JPanel and JDialog size on windows platform with screen size from 13inch to 15inch. What I refer as proper size is that all the components in JPanel and messages at JDialog are properly shown.
However, when running under Ubuntu linux with Genome/Kde desktop, I find the not all components or messages are fully shown and it appears that either width or height is not enough and the GUI interface is cropped
Anybody has ideas of how to fix it?
To have consistent UIs in multiple platforms you have to use LayoutManagers.
http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html
There are several graphical editors that support creating swing user interfaces using LayoutMaganers. One example is WindowBuilder for Eclipse: http://www.eclipse.org/windowbuilder/
Call Window.pack() for your JDialog before showing it to make the window just big enough to fit all the components in it. This requires that you are using layout managers.
I am making some changes to an existing application whoose screens have been implemented by using awt components. Using swing in the new elements will make life easier but i know that there are some problems of mixing swing and awt components.
What i would like to know is:
Prior to java 6 what problems might arise when someone adds swing components to an awt container?
(My appliation has custom mdi which every window is an awt panel. What I would realy like to do is use the same awt panel as my window and implement everything inside of it with swing using java 1.5)
In some forums people says that after java6u? some of the problems of mixing awt and swing components how been fixed. is there any problem still exists that you know of ?
See Mixing Heavyweight and Lightweight Components for answers to both your questions.
Here is an example of the problem.
A simple question: Is it possible to view gui of java Swing library and lwjgl 3D scene in the same window without using any additional gui libraries? How?
You can use the method Display.setParent(java.awt.Canvas) to put the LWJGL display on a canvas. You can then incorporate this canvas into your Swing GUI. Please note that there may be slight performance issues with said approach.