'Make a JNLP Web-Start applet resizable
We have an applet used to run our app in-browser, but we also provide a JNLP web-start option. When the web-start window launches, it is not resizable or maximizable and we want to make this possible.
I initially thought it be a simple setting in the JNLP file but now I'm not sure. How should I be approaching this?
Solution 1:[1]
There is no setting in the JNLP that caters for a resizable applet viewer (which is what JWS uses to show floating applets).
OTOH a little bit of hackery might get you there. I can recall doing this some (long) time ago. I think from memory it basically involved getParent() in a loop until null, the last component before that was a JFrame. Once you have a reference to the frame, you can call setResizable(true).
In fact, (considers) you might also look into JComponent.getTopLevelAncestor() for getting a reference to the root frame. AFIU that method did not exist when I tried the experiment. (Yes, it was that long ago.)
Of course, an overall better strategy is to create a hybrid application/applet. Embed the applet into a browser, and launch the frame by JWS. This provides full control over the GUI.
Solution 2:[2]
Here's a bit of code I added at the end of my init method that made my applet resizable. My class extends JApplet.
Window window = SwingUtilities.windowForComponent(this);
if (window instanceof JFrame) {
JFrame frame = (JFrame) window;
if (!frame.isResizable()) {
frame.setResizable(true);
}
}
Hope this helps.
Solution 3:[3]
I still have this problem even though is 2022.
No, I am not part of the dev team and I do not have access to source code.
What I did was use shell script to change the window size in the JNLP file to my liking every time I downloaded the JNLP.
It's not resizable but of course I can change window size in shell script and restart JNLP application.
TMPFILE=/tmp/app-resized.jnlp
cat ~/Downloads/app.jnlp | sed -e 's/width="1470" height="1250"/width="1024" height="768"/' > $TMPFILE
rm ~/Downloads/app.jnlp
javaws $TMPFILE
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andrew Thompson |
| Solution 2 | jpllosa |
| Solution 3 | Antti Rytsölä |
