Java Forum / GUI / September 2007
Applets automatically resizing when page size changes
Qu0ll - 29 Aug 2007 14:54 GMT I know almost nothing about applets so please excuse the possible lameness of this question.
Can someone tell me if it's possible for an applet to adjust its size (i.e. the amount of the web page it takes up) when the size of the web page itself changes? What I mean is that when you increase the size of the browser window then the web page (HTML) usually automatically adjusts its own size to accommodate the new browser window size and the contents of the page are laid out accordingly. Is it possible to have the applet do something similar? My only experience with applets was when they used to be annoying little grey boxes but I am hoping that the platform has improved and I can port my Swing applications to the web (and yes I know about JNLP which is not what I am looking for).
 Signature And loving it,
-Q _________________________________________________ Qu0llSixFour@gmail.com (Replace the "SixFour" with numbers to email me)
Andrew Thompson - 29 Aug 2007 15:56 GMT >I know almost nothing about applets so please excuse the possible lameness >of this question. Applets are not for noobs. You are better off looking to a web start launched JFrame (which is automatically resizable), or the same launch for an applet (though that requires a bit of hackish tweaking, to make it resizable in the applet viewer).
>Can someone tell me if it's possible for an applet to adjust its size (i.e. >the amount of the web page it takes up) when the size of the web page itself >changes? Yes, no, maybe. Depends on the browser/VM combo.
1) You might look to JavaScript to check the page size regularly, and then resize the applet accordingly. Obviously that will fail if JS is disabled.
2) Use a combination of HTML and CSS and 'hope for the best'. Here are my best experiments. <http://www.physci.org/test/resize/>
>...port my Swing applications to the web (and yes I > know about JNLP which is not what I am looking for). Applets and Swing embedded in web pages. 'Welcome to a world of trouble'.
Why does web start *not* provide what these applications need? There are a very few applets that rely of interaction with JS that simply *cannot* be run using web start, but very little else prevents a web start launch, and something coming from being a desktop application is unlikely to rely on use of javascript.
 Signature Andrew Thompson http://www.athompson.info/andrew/
Qu0ll - 30 Aug 2007 03:04 GMT OK thanks for the info Andrew. I am not a Java n00b - just applets and everyone has to start somewhere with them. I can report that your resize applet runs well in both IE 7.0 and Firefox 2.0.1 but when I click on the link to display the source I get a blank page in IE and a garbled mess in Firefox which looks the unformatted code of the JSP.
Where can I get the source to the applet otherwise? It behaves in exactly the way I would like mine to behave.
 Signature And loving it,
-Q _________________________________________________ Qu0llSixFour@gmail.com (Replace the "SixFour" with numbers to email me)
Andrew Thompson - 30 Aug 2007 05:24 GMT ...
>Where can I get the source to the applet otherwise? The point is not the applet. The applet does not do *anything* specific to cause the resize. The only aspect the applet has that helps the entire demo., is that is it amenable to resizing.
It is the HTML and styles (CSS) in the page that cause the applet to either be resized, or not (in the case of the browsers that fail).
As far as that 'noob' comment goes, I did not mean it quite the way it came out sounding. The point I was trying to make was that there are an entire new world of potential problems when it comes to the browser interaction (or rather, the interaction of an applet with a VM/Browser (with Plug-Ins), the HTML, CSS and JS, other elements in the same page..).
The 'latest' little quirk I heard of, was that in some patch of FF, scrolling *down* will cause all applets in the page to reload (the bug does not manifest when scrolling up).**
So, as a trivial e.g. of my warnings.
Is your applet amenable to working under those conditions? Are you prepared to write a 'fix' for the broken FF behaviour? Are you ready to perform patches to the applet the *next* time a browser develops a problem?
Despite my seeming success in the example you saw, I decided that because it failed in Opera (badly), that it was unusable on the 'big bad' WWW.
** And if that FF report is in any way surprising, I stand by my 'noob' (to applet deployment) comment.
Since it seems to have been trimmed in the reply, I will ask again..
>> Why does web start *not* provide what these >> applications need?
 Signature Andrew Thompson http://www.athompson.info/andrew/
Qu0ll - 30 Aug 2007 07:33 GMT > The point is not the applet. The applet does not do *anything* > specific to cause the resize. The only aspect the applet has > that helps the entire demo., is that is it amenable to resizing. > > It is the HTML and styles (CSS) in the page that cause the applet > to either be resized, or not (in the case of the browsers that fail). OK then, do you provide guidelines as to the requirements on the HTML/CSS side for applet resizing or could you recommend a good source for such guidelines?
> As far as that 'noob' comment goes, I did not mean it quite the > way it came out sounding. The point I was trying to make was > that there are an entire new world of potential problems when > it comes to the browser interaction (or rather, the interaction of > an applet with a VM/Browser (with Plug-Ins), the HTML, CSS and > JS, other elements in the same page..). There was no problem on my side with the n00b remark but I wanted you to know that I do know my way around Java and especially Swing. However when it comes to web development them I certainly am a newbie so I appreciate the time you have taken to assist me on this matter.
> The 'latest' little quirk I heard of, was that in some patch > of FF, scrolling *down* will cause all applets in the page > to reload (the bug does not manifest when scrolling up).** Nasty.
> So, as a trivial e.g. of my warnings. > > Is your applet amenable to working under those conditions? > Are you prepared to write a 'fix' for the broken FF behaviour? > Are you ready to perform patches to the applet the *next* > time a browser develops a problem? Well at this stage I am just investigating the possibility of porting my Swing apps to the web in one way or another. If I do decide to go down the applet route then I would do whatever it took to get it to work on all platforms.
> Despite my seeming success in the example you saw, > I decided that because it failed in Opera (badly), that it > was unusable on the 'big bad' WWW. I think you are being too hard on yourself. If your technology works in IE and FF then that covers well over 90% of all browsers. I don't expect to ever achieve 100% coverage.
> Since it seems to have been trimmed in the reply, > I will ask again.. > >>> Why does web start *not* provide what these >>> applications need? Sorry, didn't mean to avoid it. It's not so much that web start can't handle my requirements - it's more that I just don't like it. Ideally I want users to be able to surf the net in their browser and perform all their interactions *in* the browser. It feels more comfortable like that where the need to switch betweens applications is obviated. I also don't like the way web start integrates with the OS - some work is needed there with application icons and shortcuts. And I am concerned about the deployment model of web start. My (limited) knowledge of it suggests that all clients of the JNLP-delivered application have to get updated at the same time even though some sites may have issues with some versions of your application and need to remain at a particular release. Also, how do you pull back a faulty release or update? There are other issues with web start that I can't recall at the moment too but the main thing is I would really like to provide a browser-based experience with a GUI application.
 Signature And loving it,
-Q _________________________________________________ Qu0llSixFour@gmail.com (Replace the "SixFour" with numbers to email me)
Andrew Thompson - 30 Aug 2007 09:30 GMT >> The point is not the applet. The applet does not do *anything* >> specific to cause the resize. The only aspect the applet has [quoted text clipped - 6 lines] >side for applet resizing or could you recommend a good source for such >guidelines? As far as the actual example goes, pull up the HTML and CSS by viewing the source of the web page in your browser. The styles (90% of the behaviour) are written directly into the page.
Guidelines? The W3C is the definitive source of recommendations for HTML and CSS. The trouble is that browser manufacturers choose which bits of the recommnedations they will implement, and how.
A classic example is this very page we have been talking about. <http://www.physci.org/test/resize/fullwnd5.html>
It is declared as HTML 4.01 transitional (but even then it has two validation errors because I neglected to specify a width/height for the first (invisible) applet).
It requires HTML 4.01 for styles - CSS, but the APPLET element was deprecated in HTML 4.01 in preference to the OBJECT element, which is not supported in Mozilla family browsers. To support applets in pure HTML 4.01 requires the horrid nested OBJECT/EMBED element, but ..what am I saying! That can *never* be pure, *valid* HTML 4.01, since the EMBED element is not defined in HTML 4.01!
Then we come to the last comment in the HTML of that page (the details are hidden in HTML comments, directly in the web page!). The page ends like this.. "... <!-- IE introduces scroll-bars unless the last three tags are together on a single line. --> </applet></body></html>"
It certainly is not specified in any spec. that you might need to put all those elements together on a single line in order to get IE to honour the layout and style of the web page!
> ...If I do decide to go down the applet route then I would > do whatever it took to get it to work on all platforms. You're a better man than me, Gungadin, if you can achieve that aim. ...
>>>> Why does web start *not* provide what these >>>> applications need? > >Sorry, didn't mean to avoid it. It's not so much that web start can't >handle my requirements - it's more that I just don't like it. ... (snip)
Answered. I cannot say I entirely agree with your caveats to web start, but the 'want it embedded in a web page' certainly answers the question.
 Signature Andrew Thompson http://www.athompson.info/andrew/
Andrew Thompson - 30 Aug 2007 06:31 GMT ...
>2) Use a combination of HTML and CSS and 'hope for >the best'. Here are my best experiments. ><http://www.physci.org/test/resize/> Your initial reply to that link had me vaguely irritated that the information there, had failed to communcicate a variety of things that it was intended to. Now I check the page, it becomes obvious the 'major link' to the discussion behind the example, was broken.
Read more, from the c.l.j.gui thread starting with this post. <http://groups.google.com.au/group/comp.lang.java.gui/msg/18b3469ff25b0614>
Just to confuse matters further, the links in that thread pointing to the test/lnf/ path of my site were apparently changed* to test/resize/ as the resizing apparently became much more important than the (relatively simple) PLAF change.
Hope that clarifies some things for you.
(Oh, and I still want to know why 'no JWS'.)
* Bad, bad Andrew. "Good URL's don't change".
 Signature Andrew Thompson http://www.athompson.info/andrew/
Qu0ll - 01 Sep 2007 00:48 GMT > 2) Use a combination of HTML and CSS and 'hope for > the best'. Here are my best experiments. > <http://www.physci.org/test/resize/> Just one question, when I open this page in IE 7.0 the applet runs straight away without any annoying prompt about unsafe controls and yet when I run my own applets I get the prompt. What do I have to do to my applet to get it to behave like yours?
 Signature And loving it,
-Q _________________________________________________ Qu0llSixFour@gmail.com (Replace the "SixFour" with numbers to email me)
Andrew Thompson - 01 Sep 2007 03:47 GMT ...
>Just one question, .. 'Famous last words' ;-)
>..when I open this page in IE 7.0 the applet runs straight >away without any annoying prompt about unsafe controls and yet when I run my >own applets I get the prompt. What 'the prompt' would you be referring to? I can make guesses, but I do not intend to. What is the message of the dialog or prompt? Please quote the exact text it is telling you.
 Signature Andrew Thompson http://www.athompson.info/andrew/
Andrew Thompson - 01 Sep 2007 11:58 GMT >... >>Just one question, .. 'Just two questions' (from past conversations, still unanswered)
>>..when I open this page in IE 7.0 the applet runs straight >>away without any annoying prompt about unsafe controls and yet when I run my [quoted text clipped - 4 lines] >What is the message of the dialog or prompt? >Please quote the exact text it is telling you. OK. Cut that down to 'one'.
Answer the *last* question, and I will consider devoting more thought to this matter. But please be specific and pay attention to what I am asking you, otherwise this is too much trouble for me to bother with*.
& while you're at that 'specific' stage, please provide a 'prompt'/'no prompt' report for all 6 URL's at the basic address we were discussing earlier, the main page, as well as *each* of the 5 examples.
Also, can you 'copy/paste' the HTML that you are pulling up in IE, for any one specific page that is 'no prompt'? You'll need to identify which URL it represents. That might reveal some intricacies of what is happening.
* Note that I do not run IE 7, so if it is the Eolas patent thing, I am unable to do any local testing, & have to rely on reports from IE 7 users.
 Signature Andrew Thompson http://www.athompson.info/andrew/
Andrew Thompson - 05 Sep 2007 04:32 GMT >>... >>>Just one question, .. [quoted text clipped - 31 lines] >patent thing, I am unable to do any local testing, >& have to rely on reports from IE 7 users. 'bump'
 Signature Andrew Thompson http://www.athompson.info/andrew/
Qu0ll - 05 Sep 2007 07:47 GMT >>'Just two questions' (from past conversations, >>still unanswered) [quoted text clipped - 31 lines] > > 'bump' Andrew, I know it is rude to ignore people trying to help you and I can assure you that I was not ignoring you. The truth is that this post of yours never appeared on my news server so I never saw it. I regard this problem as being solved because I do not experience any security warnings when I run the applet from a server. I am not concerned that I get the warning when I run it from the local file system as this will never be done in practise. Once again, sorry for not being able to reply to your post and thank you for your assistance.
 Signature And loving it,
-Q _________________________________________________ Qu0llSixFour@gmail.com (Replace the "SixFour" with numbers to email me)
Roedy Green - 01 Sep 2007 05:39 GMT >Just one question, when I open this page in IE 7.0 the applet runs straight >away without any annoying prompt about unsafe controls and yet when I run my >own applets I get the prompt. What do I have to do to my applet to get it >to behave like yours? note how his Applet is invoked, jarless. That means it can't possibly be signed.
<applet code="PlafChanger.class" codebase="." alt="Pluggable Look'n'Feel Changer appears here if Java is enabled" width='100%' height='250'> <p>Pluggable Look'n'Feel Changer appears here in a Java capable browser.</p> </applet>
 Signature Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Andrew Thompson - 01 Sep 2007 06:03 GMT >>Just one question, when I open this page in IE 7.0 the applet runs straight >>away without any annoying prompt about unsafe controls and yet when I run my [quoted text clipped - 3 lines] >note how his Applet is invoked, jarless. That means it can't possibly >be signed. You are correct. It sure is not signed.
But I suspect this does not come down to 'trusted applets' like I think you are referring to, but instead MS' response to the EOLAS patent.
We will know more when the exact text of the warning dialog gets posted.
 Signature Andrew Thompson http://www.athompson.info/andrew/
Qu0ll - 01 Sep 2007 07:57 GMT > note how his Applet is invoked, jarless. That means it can't possibly > be signed. [quoted text clipped - 9 lines] > browser.</p> > </applet> Roedy, I think there is more to it than that because I copied his HTML *exactly* and just changed the class name of the applet to mine and it still comes up with the security warning prompt. Maybe it has something to do with the way I am running it. I am not using any form of server at this stage and am simply starting the web page and HTML from the local file system. I notice too that all the JDK demo applets cause the security prompt as well.
 Signature And loving it,
-Q _________________________________________________ Qu0llSixFour@gmail.com (Replace the "SixFour" with numbers to email me)
Roedy Green - 01 Sep 2007 08:11 GMT >Roedy, I think there is more to it than that because I copied his HTML >*exactly* and just changed the class name of the applet to mine and it still >comes up with the security warning prompt. Are you using IE 7? Part of Bill Gates' war on Java is that phony security warning message.
If you are using Internet Explorer 7 you must allow blocked content permission for Active X to run. This also gives permission to Java to run. Click the Information bar, and then click Allow blocked content.
Bill insists you permit the dangerous Active X to run in order to get the perfectly safe Java.
 Signature Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Qu0ll - 01 Sep 2007 08:19 GMT > Are you using IE 7? Part of Bill Gates' war on Java is that phony > security warning message. [quoted text clipped - 5 lines] > Bill insists you permit the dangerous Active X to run in order to get > the perfectly safe Java. I am indeed using IE7 but that doesn't explain why Andrew's applet loads without the warning and mine doesn't (using the exact same HTML and browser).
 Signature And loving it,
-Q _________________________________________________ Qu0llSixFour@gmail.com (Replace the "SixFour" with numbers to email me)
Roedy Green - 01 Sep 2007 12:38 GMT >I am indeed using IE7 but that doesn't explain why Andrew's applet loads >without the warning and mine doesn't (using the exact same HTML and >browser). Perhaps at some point in past you allowed blocked content for Andrew's site.
Try one my applets. See http://mindprod.com/applet/applets.html You should see the same problem as on your site.
 Signature Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Qu0ll - 01 Sep 2007 13:38 GMT >>I am indeed using IE7 but that doesn't explain why Andrew's applet loads >>without the warning and mine doesn't (using the exact same HTML and [quoted text clipped - 5 lines] > Try one my applets. See http://mindprod.com/applet/applets.html > You should see the same problem as on your site. Thanks, I think I've sorted it out - mostly. I tried your applets and they also run without any security warning. Further, I deployed my applet to a web server and accessed it on the same machine and I too don't get any security warnings. Same goes for accessing it on another machine via the server. So it must be that when you access an applet from the local file system IE needs to warn you about security for some strange reason. I do know that there are differences in the security profiles for local files/intranet compared to internet but I would have expected that the extra security would have been applied to internet access and not the local file system. Bizarre!
 Signature And loving it,
-Q _________________________________________________ Qu0llSixFour@gmail.com (Replace the "SixFour" with numbers to email me)
Roedy Green - 02 Sep 2007 11:56 GMT > I do >know that there are differences in the security profiles for local >files/intranet compared to internet but I would have expected that the extra >security would have been applied to internet access and not the local file >system. Bizarre! That is peculiar. Have you got some peculiar security settings for local intranet configured in IE tools/Internet/security to distrust yourself more than others?
Do you have a custom policyfile? see http://mindprod.com/jgloss/policy.html
 Signature Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Qu0ll - 02 Sep 2007 21:36 GMT > That is peculiar. Have you got some peculiar security settings for > local intranet configured in IE tools/Internet/security to distrust > yourself more than others? No, I have checked and the security settings for the intranet are no more restrictive than the internet settings.
> Do you have a custom policyfile? see > http://mindprod.com/jgloss/policy.html No, I don't.
Roedy, have you tried running an applet from the local file system? Can you try running one of the JDK demo applets for example and seeing if you encounter the same thing?
 Signature And loving it,
-Q _________________________________________________ Qu0llSixFour@gmail.com (Replace the "SixFour" with numbers to email me)
Roedy Green - 03 Sep 2007 07:59 GMT >Roedy, have you tried running an applet from the local file system? Can you >try running one of the JDK demo applets for example and seeing if you >encounter the same thing? I do it all the time. See http://mindprod.com/applet/applets.html However, with IE7 I must kiss Bill's a.s with that stupid "allow blocked content" gambit each time.
MS does all they legally can to screw Java. Use a different browser. See http://mindprod.com/jgloss/browser.html
 Signature Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Qu0ll - 03 Sep 2007 10:11 GMT >>Roedy, have you tried running an applet from the local file system? Can >>you [quoted text clipped - 4 lines] > However, with IE7 I must kiss Bill's a.s with that stupid "allow > blocked content" gambit each time. So why you have to kiss his arse when you run the applet from the local file system but not if it's loaded over the internet?
> MS does all they legally can to screw Java. Use a different browser. That's fine for me but I can't make all the users of my applets use a different browser too. Most will always use IE.
 Signature And loving it,
-Q _________________________________________________ Qu0llSixFour@gmail.com (Replace the "SixFour" with numbers to email me)
Roedy Green - 14 Sep 2007 16:33 GMT >So why you have to kiss his arse when you run the applet from the local file >system but not if it's loaded over the internet? It is a decision IE is making. It somehow considers content from your own local hard disk more dangerous than stuff out on the Internet. It makes no sense, especially when I configured IE to use lower security on my intranet than the Internet.
 Signature Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
John Burton - 21 Sep 2007 19:14 GMT >>So why you have to kiss his arse when you run the applet from the local >>file >>system but not if it's loaded over the internet? This explains why and how to bypass the warning http://msdn2.microsoft.com/en-us/library/ms537628.aspx
Andrew Thompson - 22 Sep 2007 05:50 GMT >>>So why you have to kiss his arse when you run the applet from the local >>>file >>>system but not if it's loaded over the internet? > >This explains why and how to bypass the warning >http://msdn2.microsoft.com/en-us/library/ms537628.aspx The MS 'Mark of the Web'!
(slaps self) I had entirely forgotten it.
One day, maybe, I am going to prepare a page listing the most problematic and common 'applet/browser gotchas'.
 Signature Andrew Thompson http://www.athompson.info/andrew/
Roedy Green - 29 Aug 2007 22:07 GMT >Can someone tell me if it's possible for an applet to adjust its size (i.e. >the amount of the web page it takes up) when the size of the web page itself >changes? see Applet.setSize. Try the experiment.
 Signature Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Qu0ll - 30 Aug 2007 03:06 GMT > see Applet.setSize. Try the experiment. Yes there is that method (which is actually in Component) and there is resize() in JApplet but the problem is how does it know when to resize itself? i.e. how does it know the surrounding page has resized?
 Signature And loving it,
-Q _________________________________________________ Qu0llSixFour@gmail.com (Replace the "SixFour" with numbers to email me)
Andrew Thompson - 30 Aug 2007 05:35 GMT >> see Applet.setSize. Try the experiment. I second 'try the experiment' (in a slew of browsers), because..
>Yes there is that method (which is actually in Component) and there is >resize() in JApplet but the problem is how does it know when to resize >itself? i.e. how does it know the surrounding page has resized? ..the ways, and forms, of the failures are fascinating.
 Signature Andrew Thompson http://www.athompson.info/andrew/
Roedy Green - 30 Aug 2007 10:45 GMT >Yes there is that method (which is actually in Component) and there is >resize() in JApplet but the problem is how does it know when to resize >itself? i.e. how does it know the surrounding page has resized? This requires JavaScript to send your Applet a message. Yucch!
Do a Google search on JavaScript, DOM, Applet and/or resize.
 Signature Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|