How to set maximum available size for JApplet?

微笑、不失礼 提交于 2019-12-24 11:15:08

问题


I am porting my desktop Swing application to an applet. The following code works perfect for JFrame entity to set a maximum available window size, considering a task bar.

GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle bounds = env.getMaximumWindowBounds();
frame.setMaximizedBounds(bounds);
frame.setPreferredSize(bounds.getSize());
frame.setLocation(0, 0);

In Eclipse Run Configurations -> My Applet -> Parameters I can select Width and Height or if applet is run from browser one would have to do:

<applet code="myJApplet" width="800" height="480">

But I would like to be able to set size dynamically depending on screen resolution. How would it be possible?


回答1:


Expanding on this previous answer, you may want to adopt a hybrid approach, which offers additional deployment options via Java Web Start. Your focus should be on developing a Container that functions well at any initial size, while avoiding common traps. Use java.util.Preferences to retain geometry that's under your control, and adapt when it's not. The details depend on the actual content, but the problem is at least well encapsulated.




回答2:


Use JavaScript, with noscript 800x600. Note, this takes much memory. Though a bit troublesome, maybe better go for a Java Webstart application.

noscript is a tag <noscript>(static html content)</noscript> in which you can put conditional HTML - when JavaScript is blocked. With JS you can have a full dynamic solution, in the noscript have a fixed size solution.




回答3:


I have found it here: http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/

<script type="text/javascript">
<!--
var w=window,d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],x=w.innerWidth||e.clientWidth||g.clientWidth,y=w.innerHeight||e.clientHeight||g.clientHeight;
//-->
</script>


来源:https://stackoverflow.com/questions/14152147/how-to-set-maximum-available-size-for-japplet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!