Java Swing GUI Size under cross-platform - java

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.

Related

Can't scale and move components in IntelliJ

I can't scale and move components in IntelliJ with its GridLayout. The problem is when I move/scale components they don't move to the exact place.
Picture (But I think you'd better check the vid out)
I uploaded a video on youtube
Here it is https://www.youtube.com/watch?time_continue=9&v=X6CF7TJ7GJg (sorry for a non-english speech)
You should learn how Java Swing Layouts work. Most layout managers do not allow you to place the components where you want (there is so called Null-layout, but it's not supported by IntelliJ IDEA).
You normally use splits, spacers and constraints to define where the components will appear and how they will resize when the form is resized.

What is a top-level window in java awt?

I found this line on the java docs tutorial site- "A Frame is a top-level window with a title and a border". Here, what is the meaning of "top-level window"?
A 'top-level window' or 'top level container' is something that can be shown on screen without having to add it to another component. We would start a GUI with a top level container, and then add panels and components to that TLC. E.G. of top level containers..
AWT - Frame, Window, Dialog ..
Swing - JFrame, JWindow, JDialog, JOptionPane ..
Java-FX - Stage (I have not used Java-FX much, so am unfamiliar with the other variants of TLCs, but see the Java-FX API docs for other examples).
See also this answer for many good reasons to abandon AWT components in favor of Swing. As to abandoning Swing for Java-FX, I'll be unwilling to do so until Java-FX is promoted to the Java API's Java docs, and makes it into the official Java Tutorial. Sun, then Oracle, has a bad habit of hyping many technologies only to later quietly drop support & development for them.
In GUI toolkits such as AWT, a top-level window is a window which is usually known to the OS (heavy-weight components).
Side note: AWT (and even Swing) is a pretty old technology. I recommend to use JavaFX where possible.
a window without a parent.
a window can have child windows alright and they have a parent then
Observe difference among these classes.
Frame is top level window because it has border and title. An instance
of frame can have a menubar. Without those it is mere is an instance
of java.awt.Window class.
Window class: It has neither border not title. Window class is not attached to nor embedded within another container.
Dialog: It has border and title. An instance of the Dialog class cannot exist without an associated instance of the Frame class.
Panel: just a generic container to hold components. Its instance provides a container to which to add components.
Note: Revert me back if further clarification is required.

Java WindowBuilder on different screen resolution

I am making a java program for Windows with GUI using windowbuilder.
I set the sizes of the components so that it would match a screen resolution of 3200x1800.
After I built the program I ran it on a different computer with a screen resolution of 1366x768. All of the components were much bigger than running the program in the high screen resolution screen.
How can I set the components to be in the same size for all screen resolutions (the components will match the screen resolution)?
dear #amitai you must have to use some layout provided by Java like gridBagLayout, BorderLayout and FlowLayout bla bla bla Adjust your components as per Layout recommendation. If you will success to adjust your components in Layout your problem will automatically solved.
These Layouts are developed for the purpose of adjusting components in a sequences for different type of resolutions. Layout are working as a container.
For brief discussion follow reference link below:
http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html
http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html

I cant figure out how to use java gui / layouts?

how can I make a gui interface with everything in order I know the borderlayout, flowlayout and gridlayout but what is panel? im so confused please help in visual basic I just dragged and dropped. im using netbeans 7.1, I can do layouts and stuff the problem is its so confusing to make all these panels and stuff and (x, y) axis where to place them I want the gui nice and neat
how can I make a gui interface with everything in order
For a single column or row, see GridLayout1 & BoxLayout2, as well as JToolBar3 & JList4.
See 'How To Use':
GridLayout
BoxLayout
JToolBar
JList
Have you seen these examples http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html ?
I was used to creating java GUI with manual coding, I mean not the drag and dropped that auto-generates the codes, so it was a lot easier for me to switch with GUI designer such as Window Builder plugin for Eclipse or the built-in swing designer of NetBeans.
I suggest you to start with the basic of Layout Managers with manual coding. Here's a good link... http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html
Start with the easiest: FlowLayout, GridLayout, and BorderLayout. These layouts are usually applied to JPanel, which is a lower level container (JFrame being the top-level container)

Why does my swing GUI look different in design than at run-time?

When I design my GUI using swing, the Swing Control Buttons are grey and the text easily fits on them. However, when I run the program the buttons become partly blue and the text no longer fits on them. Why does my program look different in the Swing Design than at run-time?
Why does my program look different in the Swing Design than at run-time?
Probably has something to do with your Look and Feel.
However, when I run the program the buttons become partly blue and the text no longer fits on them.
Probably because you are not using layout managers. Layout managers will make sure components are displayed properlly, even when switching between LAF's.
I can't guess what tool you are using to create your GUI but you are doing something wrong with the tool. If you need more help then post your SSCCE that demonstrates the problem.
I suppose you're using some GUI builder. Netbeans gui builder displays preview with native LaF, while program runs with default Metal LaF, which has different margins for components and font size. Either change LaF in your program to the one that works best for your layout, or make your components larger.

Categories

Resources