Java desktop application with MIG layout on different screen resolutions - java

I am working on a desktop application in Java which uses Swing with MIG layout for building the GUI. I have a lot of drag&drop actions which require "fixed" screen positions (the application works with plugs and sockets). Currently we support only one screen resolution
Is it possible to build the GUI so that it is scaled somehow according to the screen resolution?
Thank you in advance

You can get the screen resolution this way:
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Set the size of your JFrame accordingly to it. (Remember to use setSize() only on Frame not on child Components with their own LayoutManager)

Related

Swing GUI not scaling from computer to computer

I designed (Netbeans Project) the swing GUI in one computer 15" screen.
Next, I moved the project to another computer 14" screen. When I launch the app in the 14" screen, it's like zooming the GUI and I can't see some part of it.
How can I let my design adjust itself from one computer to another?
Ps : In the GUI editor of netbeans, the size is the same in both computers
Update
I don't know if layout manage will solve it as they said in comments. I've just notice my Windows 10 displays 125 % zoom scaling on 1920 x 1080 resolution. When I switched to 100%, though all other applications of the computer looked aweful, the design I made in Netbeans looked exactly the same. What can I do then ? I think it's more related to Windows scaling than Swing's LayoutManager features. Am I correct ?
You need to use layout managers. Layout managers will organize your components in different ways depending on screen size, aspect ratio, etc.
Depending on what kind of GUI you want, you are going to choose a different layout manager. Once you have picked a layout manager, you can pass it to a JPanel on construction
JPanel panel = new JPanel(new FlowLayout());
More on info on how to use layout managers, here

swing output is to small in netbeans

look at the image and you will understand what my problem
that's happened in this computer which is 4k UHD
this problem was under netbeans itself but i fix it using netbeans-ide-scaling-on-windows-8-10
when i tried to test it under swing this problem appear again.
setSize and setFont(new Font(MAX_FONT_SIZE)) are not what i'm looking for.
my working environment is:
windows 10 home
netbeans v8.0.2
May be you are not preparing the dimension on jframe.
Go to the design panel and click jframe.
set the preferredSize, width, height to change the size of jframe on properties window.
I think that it will be work.

Swing -> JavaFX, how to create custom graphical applications using JavaFX

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.

OpenGL inside a JFrame

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

UI Change in Swing application across platforms

My Swing Application's GUI is built using Window Builder Pro GUI editor. Layouts used are MigLayout and AbsoluteLayout. Application is developed using Windows Machine, So UI is well aligned and neat in Windows, but when I run the same application in Mac OS X, Application's Frame couldn't accommodate the components inside its bounds. I mean, size of Components inside the frame changes across platforms. When I give extra space(Increased frame bounds), it looks nice in Mac but weird in Windows. Is there any way to have Frame or Panel to grow with respect to its contents or Components.
Don't use the absolute layout. Layout managers are used precisely to avoid the kind of problems that you're facing.
Assuming you used AbsoluteLayout because none of the existing layout managers suited your needs,
Have a look at Creating a Custom Layout Manager and use one instead of AbsoluteLayout.(Before that make sure none of the present layout managers suit your need)

Categories