Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 7 Mar 1998 23:52:38 +1100 (EST)
From:      "Simon J. Gerraty" <sjg@quick.com.au>
To:        freebsd-java@FreeBSD.ORG
Subject:   JVM bug or user error?
Message-ID:  <199803071252.XAA01494@zen.quick.com.au>

next in thread | raw e-mail | index | archive | help
hi,

I have been testing some awt behaviour in my native NetBSD jdk (uses
lesstif), The reason I'm posting here is that the current FreeBSD JDK
using Motif shows the same behaviour (bug?).  Note that real apps so
far have worked fine with the FreeBSD JDK on NetBSD.

Since all my tests were run on a NetBSD-1.3 box I would appreciate
it if someone could compile the app and run it on a FreeBSD system.

Below is a simple test app which should throw up a username/passwd
dialogue.   It is hacked from modeFrame11.java from the Java AWT Reference
book from O'Reilly & Assc. The changes made are simply to allow its
behviour to be changed at runtime.

Basically if you compile modeFrameL.java and run 

java modeFrameL

this explicitly calls resize(250,125) and you get:

getPreferredSize(): x=0, y=0

printed out, and a correctly sized popup window.

If you run "java modeFrameL a", it skips resize() and calls pack(),
you now get:

getPreferredSize(): x=217, y=102

and a 2x2 sized popup!

If you run "java modeFrameL a b", it does the resize() followed by
pack() and you get:

getPreferredSize(): x=217, y=102

and a reasonably sized popup.

What is going on?  It appears that getPreferredSize() returns 0x0
until pack() has been called.  Which is interesting as one of the
things that pack() does is setSize(getPreferredSize()).  However once
pack() has been called setSize() seems to have little/no effect - note
that I force a size change before calling setSize() again.

BTW I've fixed much of the lesstif lossage by simply setting
awt.frame.*Inset=0 in the System properties (undoes a Motif specific
hack in MFramePeer), this also stops dialogs from poping up with
_huge_ windows - they now get tiny ones :-) I've been using the
modeFrame app to trace under jdb and gdb to see what is going on.

Anyway, like I said, the surprise was that in this case the FreeBSD
JDK showed exactly? the same behaviour whereas for real apps dialogs
etc are sized ok.


--sjg

// This example is from the book _Java AWT Reference_ by John Zukowski.
// Written by John Zukowski.  Copyright (c) 1997 O'Reilly & Associates.
// You may study, use, modify, and distribute this example for any purpose.
// This example is provided WITHOUT WARRANTY either expressed or
import java.awt.*;
class modeTestL extends Dialog {
    TextField user;
    TextField pass;
    modeTestL (Frame parent) {
        super (parent, "Mode Test", true);
        add ("North", new Label ("Please enter username/password"));
        Panel left = new Panel ();
        left.setLayout (new BorderLayout ());
        left.add ("North", new Label ("Username"));
        left.add ("South", new Label ("Password"));
        add ("West", left);
        Panel right = new Panel ();
        right.setLayout (new BorderLayout ());
        user = new TextField (15);
        pass = new TextField (15);
        pass.setEchoCharacter ('*');
        right.add ("North", user);
        right.add ("South", pass);
        add ("East", right);
        add ("South", new Button ("Okay"));
	// If we call pack(), getPreferredSize() returns something
	// useful rather than 0x0,
	// but a subsequent setSize() has no effect - we
	// end up with a 2x2 window!
	// 
	// pack();
	// but the original call here works ok.
	//      resize (250, 125);
    }
    public boolean handleEvent (Event e) {
        if (e.id == Event.WINDOW_DESTROY) {
            dispose();
            return true;
        } else if ((e.target instanceof Button) &&
             (e.id == Event.ACTION_EVENT)) {
            hide();
        }
        return super.handleEvent (e);
    }
}

public class modeFrameL extends Frame {
    modeFrameL (String s) {
        super (s);
        resize (100, 100);
    }
    public static void main (String []args) {
        Frame f = new modeFrameL ("Frame");
        modeTestL d;
        d = new modeTestL (f);
	// some changes so we can run multiple tests...
	if (args.length != 1) {
	  // this works
	  d.setSize (250, 125);	// originally in modeTestL.<init>
	}
	if (args.length > 0) {
	  d.pack();
	}
	Dimension xy = d.getPreferredSize();
	System.err.println("getPreferredSize(): x=" + xy.width + ", y=" + xy.height + "\n");
	if (xy.width > 0) {
	  // force setSize() to do something.
	  xy.width++;
	  xy.height++;

	  d.setSize(xy);
	}
        d.show ();
        d.dispose();
        f.add ("North", new Label (d.user.getText()));
        f.add ("South", new Label (d.pass.getText()));
        f.show ();
    }
    public boolean handleEvent (Event e) {
        if (e.id == Event.WINDOW_DESTROY) {
            hide();
            dispose();
            System.exit (0);
        }
        return super.handleEvent (e);
    }
}

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199803071252.XAA01494>