// remove borders
dontUseBorderForRootPanel();
// ensure attached
invokeAttachScript();
// apply size to get actual widget size
Dimension resourceSize = getResourceSize();
doApply(resourceSize);
// get the real "size" to include full widget
Dimension size = getExpandedSize();
// correct size to fit into top-level root panel
Dimension correctedSize = new Dimension(resourceSize);
correctedSize.width -= size.width - resourceSize.width;
correctedSize.height -= size.height - resourceSize.height;
// apply corrected size to the widget
if (correctedSize.width > 0 && correctedSize.height > 0) {
doApply(correctedSize);