Java (Eclipse) WindowBuilder setting maximum dimensions - java

I have built a window application using the SWT WindowBuilder in Eclipse. I want the window to be a set size whilst the application is running.
This means that I do not want the user to be able to resize the window e.g. disable window resizing and if that is not possible then I would like to ensure that the window has a maximum size (this is called bounds in Eclipse).
Looking at the official documentation I cannot find a setMaximumSize. Only a setMinimumSize (which I have already specified).
Official documentation link
Is there a way of getting the size of the window if it changes (such as an event handler). If there is how would I use an event handler to monitor size and change the size back to 300,600 if it were to change?
I only want the window size to be 300 width and 600 height. IS THAT TOO MUCH TO ASK!? :'(
How could I go about setting an infinite loop to constantly set the dimensions? What would the impact of this be on the performance of the application?

Related

Draw a window only on top of an external application in Java

I am trying to create a JWindow that sits on top of an external application.
I want the window to resize whenever the external application resizes (to match it) and be only on top of the external application and not everything else. (I can't use setAlwaysOnTop(), because it would be always on top of everything).
By modifying code from the first answer from here I am able to find the external window title (for example Untitled - Notepad) and its handle if needed.
Using code from the first answer from here, I can get the dimensions of an external window from it's window title.
The problem with finding the dimensions from the code at the second link is that I have to always loop and check them (which is not optimal) and it isn't helpful in putting my window only on top of the external one.
Is there a way to implement what I want in Java? Ideally, I would (using JNA?) make a listener to the messages (WinEvents?) the OS sends to the external program to resize it, gain/lose focus etc and handle them somehow.

Java VM argument to set the windows position

is it possible to start a java application with an argument that sets the window position and target screen index?
I run my java project using IntelliJ and want it to start on the secondary screen. Currently I always have to drag it on my own every time I run the application. This is annoying because the window size is higher than the first screen size.
Thank you.

Java Swing Background image repeat and maximized window

I want to make my application header repeated image like similar to ccleaner application header , below. I want to also put logo right top corner but when I maximizing the window , it stays in the middle. I am currently using netbeans.
Similar to ;
CSS Background Repeat ,
Okay, well do you have an attempt within your netbeans project? Something visual like a screen shot of your running application that we can work with.
If you have set your panel to the size of the JFrame then you have two options.
1. Lock the JFrame from resizing at all: Prevent Window resizing on Java (Netbeans)
2. Make the application scale/resize with the JFrame: JFrame Resizing in Desktop Application - NetBeans
Let me know if those help.
A lot of Netbeans (in terms of sizing/responsiveness) is about setting the Frame/Panel/ect... attributes so that they are all the same (locked or re-size'able)

Fixed size swing GUI changes when using different resolution

I have a small java application with a swing gui. I have set a fixed size for the window and everything works really well. But when using the GUI on different screens, the objects seem to have moved slightly. (Labels not showing their entire text etc,...) I think the difference lies in the aspect ratio of the screen but is there any way to counter this?
The way to counter it is to not used fixed size windows.
I agree with Bryan. There are many reasons - the screen resolution, localization (if you do so), different look-and-feels and rendering depending on the platform and/or JVM version. Swing's layouts are flexible enough to do everything you want without fixing the frame size. Otherwise you are going to implement your rendering engine to calculate everything which is rendered.

NetBeans (Java Swing): Set window size

This is driving me crazy. When I set an appropriate size for my window in design-mode it just ignores this size and uses something else when I compile and run. Even tough I set the minimumSize and preferredSize it just ignores this... Why? How can I set my own size?
Even if you've set the size with minimumSize and preferredSize, you might have forgotten to call Window.pack() in which Swing will resize the components (and all of it's subcomponents) according to the sizes set.
You call it in your window (or whatever is building your window) after all the preferred sizes are set.
Alternatively you can use the Component.setSize() method but it comes with some caveats.
Have you checked if you really set the size of the JFrame or of a contained JPanel?
Have you tried setSize?
I've found myself in a similar situation while using netbeans ide. I had a read of the following thread, that helped:
http://forums.netbeans.org/ptopic28011.html
Seems as though the swing application framework is saving the app's window size in a subfolder within your home dir (for Windows, the "Application Data" folder, for Linux, in your "~/" home folder).
For example, for my application 'CrapApp', swing had saved some last-window-size info into the sub-folder "~/.CrapApp/", into a file called "mainFrame.session.xml".
So no matter how I re-sized the window within the designer, upon running, it seemed to have ignored it and instead loaded the window size from the preferences within this sub-folder.
So my solution was to delete this preserved-settings sub-folder, eg, in my case, "rm -rf ~/.CrapApp/"
Then the problem went away and I could re-size within the designer and run the app with this re-sized window now visible.
This made me want to learn what triggered this issue. I noticed that simply running the app within the netbeans ide and closing it didn't generate the sub-folder.
After a bit of tinkering with my app, I noticed the following action triggered the generation of this "~/.CrapApp/" sub-folder.
Going to my app's "Help >> About"
Click the "Close" button in the about dialog that appears
Exit the app
And now the "~/.CrapApp/" sub-folder re-appears. This help/about dialog was auto-generated by netbeans ide, so I didn't really tinker with it, but this seems to have been the culprit in my case.
Perhaps it may be a bug in the netbeans ide, I'm using a somewhat old version (v6.8), which seems roughly from the era of your original post too.

Categories

Resources