About Java applets sizes

Koos Vriezen koos.vriezen at xs4all.nl
Fri Feb 21 23:30:04 GMT 2003


Hi,

Looking why kjas with kjavaappletviewer sometimes failed to correctly
resize applets, I wondered why would this be needed in the first place.

This is what happens when an applet is created:
- a JFrame is created and a JPanel is added to the center of its
  BorderLayout.
- next a call to frame.pack() which resizes the frame to something small
- the frame is embedded in a QXEmbed widget and resized by khtml
- createApplet adds an applet in the center of the panel's BorderLayout

So where does the resizing of the applet fit in? The only place I can
justify is during the initialization phase of the applet, because it's
hidden there. A resize of QXEmbed will automatically resize the applet
because of the BorderLayout. (eg, an applet calls AppletStub.appletResize(w,h)
and by kjas protocol this resizes the widget/kpart, BorderLayout resizes
the applet).

Attached a patch for testing which strips all this resizing (well
most of it :) In my tree this makes kjavaappletviewer work more nicely
with kjas.

Koos
-------------- next part --------------
Index: org/kde/kjas/server/KJASAppletStub.java
===================================================================
RCS file: /home/kde/kdelibs/khtml/java/org/kde/kjas/server/KJASAppletStub.java,v
retrieving revision 1.36
diff -u -3 -p -r1.36 KJASAppletStub.java
--- org/kde/kjas/server/KJASAppletStub.java	19 Jan 2003 15:09:33 -0000	1.36
+++ org/kde/kjas/server/KJASAppletStub.java	21 Feb 2003 23:15:44 -0000
@@ -127,7 +127,7 @@ public final class KJASAppletStub
     }
     
     void createApplet() {
-        panel = new KJASAppletPanel( appletSize );
+        panel = new KJASAppletPanel();
         frame = new JFrame(windowName);
         // under certain circumstances, it may happen that the
         // applet is not embedded but shown in a separate window.
@@ -195,7 +195,7 @@ public final class KJASAppletStub
                 app.setVisible(false);
                 panel.setApplet( app );
                 
-                app.setSize(appletSize);
+                app.setSize(panel.getSize());
                                 
                 context.showStatus("Initializing Applet " + appletName + " ...");
                 
@@ -218,8 +218,7 @@ public final class KJASAppletStub
                 stateChange(INITIALIZED);
                 loader.removeStatusListener(panel);
                 app.setVisible(true);
-                app.setSize(appletSize);                
-                app.validate();
+                panel.validate();
                
                 context.showStatus("Starting Applet " + appletName + " ...");
                 // stop the loading... animation 
@@ -334,10 +333,6 @@ public final class KJASAppletStub
             return app;
     }
 
-    Dimension getAppletSize()
-    {
-        return appletSize;
-    }
     /**
     * get a parameter value given in the <APPLET> tag 
     * @param name the name of the parameter
@@ -377,7 +372,6 @@ public final class KJASAppletStub
                 Main.debug( "Applet #" + appletID + ": appletResize to : (" + width + ", " + height + ")" );
                 Main.protocol.sendResizeAppletCmd( context.getID(), appletID, width, height );
                 appletSize = new Dimension( width, height );
-                panel.setAppletSize( appletSize );
                 //pack();
             }
         }
Index: org/kde/kjas/server/KJASAppletPanel.java
===================================================================
RCS file: /home/kde/kdelibs/khtml/java/org/kde/kjas/server/KJASAppletPanel.java,v
retrieving revision 1.1
diff -u -3 -p -r1.1 KJASAppletPanel.java
--- org/kde/kjas/server/KJASAppletPanel.java	17 Oct 2002 20:05:34 -0000	1.1
+++ org/kde/kjas/server/KJASAppletPanel.java	21 Feb 2003 23:15:44 -0000
@@ -19,7 +19,6 @@ import java.net.URL;
  */
 public class KJASAppletPanel extends javax.swing.JPanel implements StatusListener {
 
-	private Dimension size;
 	private Image img = null;
 	private boolean showStatusFlag = true;
 	private Font font;
@@ -28,26 +27,13 @@ public class KJASAppletPanel extends jav
 	/**
 	 * Constructor for KJASAppletPanel.
 	 */
-	public KJASAppletPanel(Dimension _size) {
+	public KJASAppletPanel() {
 		super(new BorderLayout());
-		size = _size;
 		font = new Font("SansSerif", Font.PLAIN, 10);
 		URL url =
 			getClass().getClassLoader().getResource("images/animbean.gif");
 		img = getToolkit().createImage(url);
 		//setBackground(Color.white);
-	}
-
-	void setAppletSize(Dimension _size) {
-		size = _size;
-	}
-
-	public Dimension getPreferredSize() {
-		return size;
-	}
-
-	public Dimension getMinimumSize() {
-		return size;
 	}
 
 	void setApplet(Applet applet) {


More information about the kfm-devel mailing list