Solved

Resizing applet in the browser

Posted on 1997-10-21
7
479 Views
Last Modified: 2012-06-21
I have an applet which runs in one of the frames of a multiframe HTML page. When the browser window gets resized, the browser resizes the frames accordingly but the applet does not get resized. looks like applet does not know of its container being resized.

What's the proper browser independent way of making sure that the applet gets resized along with the browser window?
0
Comment
Question by:msmolyak
7 Comments
 
LVL 3

Expert Comment

by:eugenem
ID: 1229360
AFAIK, you cannot resize applet in browser because applet size is specified by parameters in </applet> tag.
0
 
LVL 10

Expert Comment

by:kollegov
ID: 1229361
Browsers allow to use % instead of
absolute pixels sizes

<APPLET CODE=check1.class
 WIDTH="50%"
 HEIGHT="50%">
</APPLET>

just checked it with my Netscape3.02Gold win95
and it work at least in this browser.
MIE3.02 screwed up on it :(.

Sure applet should get it sizes each time
it makes repainting to fit new sizes.

Most of referenses says: not allowed, but
you see it's not true. I'd better say not supposed
to give you this ability, but some browsers give
it to you.

Sure if want to have browser independent way
you do not have this ability.
 

0
 
LVL 5

Author Comment

by:msmolyak
ID: 1229362
Based on my experimanetation with applet resizing I found out that the applet resizes correctly in the frame in MS IE 3.x but does nor resize in Netscape 3.x and 4.x unless you explicitly reload the frame.
Based on kollegov's answer in Javascript group I put a resize event handler in Netscape 4.x so that the applet is reloaded each time the browser or frame window is resized.
I tried to get a parent container of the applet and observe what happens to it. In Netscape it gets sized when the applet is initialized or reloaded and the browser does not bother to resize it when the browser window gets resized.
Any idea why such simple and obvious resizing support is missing?
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 5

Author Comment

by:msmolyak
ID: 1229363
Having to choose between the two proposed answers I would opt to give points to kollegov (you can claim the points).
0
 
LVL 1

Accepted Solution

by:
toml032697 earned 50 total points
ID: 1229364
Here is a small piece of code which resizes an applet in the browser it works fine in both Netscape and IE 3.x. This code doesn't work very well in IE4.0 (you have to make the browser window smaller and reload and then making it larger then it will resize it properly). In IE 4.0 you can use setBounds() it should work, but I've not tested it. But here is the code which works in Netscape and IE 3.x:

import java.applet.*;
import java.awt.*;

public class Resize extends Applet {
  Dimension dim;
  Panel p=new Panel();

  public void init() {
    dim=size();

    p.setLayout(new BorderLayout());
    p.add(new Button("Hello, world!"));

    setLayout(null);
    add(p);
  }

  public void start() {
    Container container=super.getParent();
    container.resize(getToolkit().getScreenSize());
    resize(getToolkit().getScreenSize());
    p.resize(dim=new Dimension(p.minimumSize()));
  }

  public void paint(Graphics g) {
    Rectangle r=g.getClipRect();

    if((r.x==0)&&(r.y==0)&&
      ((dim.width!=r.width)||(dim.height!=r.height))) {
      p.resize(dim.width=r.width,dim.height=r.height);
      validate();
    }
  }
}

The idea in this small applet is that the applet is resized so that it will be larger than the applet ever will be. So I chose to resize it to the same as the screen resolution. Then you get the visible are of the applet with getClipRect() and resize the applet to the same size.

There are some "bugs" in this implementation. If you move another window so that it partly overlaps the applet and then minimizes the window then the applet is resized to the size of the non-overlaping area. This can be fixed by doing an extra repaint after the applet have been resized.

           -Tom
0
 
LVL 5

Author Comment

by:msmolyak
ID: 1229365
Tom,

Thank you for an answer, it seems to behaving much better than anything I've seen before.  One question though. I noticed that when you resize the browser (I used Navigator 4.03) in horizontal direction, it resizes correctly. However, when you resize the browser vertically, the applet does not change size. Any ideas?

Michael
0
 
LVL 1

Expert Comment

by:toml032697
ID: 1229366
Yes, I know that. I think that it is a bug in Netscape, as it never calls resize() when the browser window is resized vertically (applies to all versions of Navigator). I suppose that the reason is that HTML doesn't need to be reformated to fit the window and per cent based resizing of applets is a undocumented feature.

      -Tom
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
firstswap challenge 20 77
micro services vs rest web services 16 105
stackato and cloud 4 85
Tomcat: Unable to run tomcat service. 2 20
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question