PRB: BorderLayout Does Not Accept Null Constraints |
When adding a component using a null constraint the following error message is appears:
This occurs when using a BorderLayout manager and calling the add(Component) method without passing a constraint.BorderLayout: cannot add to layout: unknown constraint: null
In the JDK 1.02 model, BorderLayout allowed you to add components with null constraints and then resize the components later. In the JDK 1.1 model, if you use a null constraint, it is treated as "Center" and the previously added "Center" component will be removed from the container. Implementing the JDK 1.1 model breaks existing JDK 1.02 applications that rely on this behavior. Microsoft's implementation of BorderLayout follows the JDK 1.02 implementation.
If you are writing a JDK 1.1 application, pass a constraint of "Center" instead of using a null constraint. For example the statement
panel.add(myComponent);
would become
panel.add(myComponent,"Center");
This behavior is by design.
The sample code below demonstrates a typical JDK 1.02 application. To avoid the error messages when running the program below, set the layout manager to 'null' instead of the default BorderLayout manger.
import java.awt.*;
class AddNull extends Frame {
public static void main(String args[])
{
Frame frame=new AddNull("AWT Layout");
frame.resize(320,200);
frame.show();
}
public AddNull(String title) {
super(title);
Button okay=new Button("OK");
Button cancel=new Button("Cancel");
Label label=new Label("Demo done.");
// setLayout(null); // uncomment to use a 'null' layout manager.
add(label);
add(okay);
add(cancel);
label.reshape(120,80,100,30);
okay.reshape(30,150,80,30);
cancel.reshape(180,150,80,30);
}
public boolean action(Event e, Object o) {
hide();
dispose();
System.exit(0);
return true;
}
} jview AddNull
Additional query words: awt null constraint layout
Keywords : kbcode AWTPkg
Version : :
Platform : WINDOWS
Issue type : kbprb
Technology :
|
Last Reviewed: December 31, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |