PDA

View Full Version : How to set absolute position on RootPanel?



Konstantin.Scheglov
21 Jun 2009, 1:03 AM
GWT: 1.6.4
GXT: 2.0-M3

Why methods Component.setPosition() and RootPanel.add(c, x, y) don't work?
This looks as bug.

public class ImageViewer implements EntryPoint {
public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();
//
LayoutContainer container = new LayoutContainer();
container.setBorders(true);
container.setSize(250, 150);
// bug#1: does not work
//rootPanel.add(container);
//container.setPosition(10, 10);
// bug#2: also does not work
//rootPanel.add(container, 100, 50);
// solution: works
rootPanel.add(container);
rootPanel.setWidgetPosition(container, 100, 50);
// finish
container.layout();
// note that in "bug" cases no "position: absolute"
System.out.println(DOM.toString(container.getElement()));
}
}

sven
21 Jun 2009, 10:42 AM
To position something you ened to make it positionable first. I am closing this issue.

Konstantin.Scheglov
21 Jun 2009, 11:05 AM
rootPanel.add(container, 100, 50);
System.out.println(DOM.toString(container.getElement()));
container.el().makePositionable(true);

1. I can not call makePositionable(true) before rootPanel.add() because component is not rendered.

2. If I call it after rootPanel.add(container, 100, 50), it still does not work, because someone cleared left/top attributes that were set by AbsolutePanel.setWidgetPositionImpl(). I don't understand why.

3. El.makePositionable() without arguments is badly designed and has wrong JavaDoc. Instead of making El positionable, it makes NOT positionable, because it calls makePositionable(false).

Why Component does not work just as normal Widget?
Why setPosition() does not make Component positionable?

If I will use separate rootPanel.add(component) and rootPanel.setWidgetPosition() (this combination sets position correctly), will something in Ext GWT break again "position: absolute" if I will call some setter or other method of Component?

sven
21 Jun 2009, 11:10 AM
3. El.makePositionable() without arguments is badly designed and has wrong JavaDoc. Instead of making El positionable, it makes NOT positionable, because it calls makePositionable(false).

The javadocs are correct. If you want it absolute positionable, you call it with the true attribute, else it will be relative positionable.

Konstantin.Scheglov
21 Jun 2009, 11:19 AM
The javadocs are correct. If you want it absolute positionable, you call it with the true attribute, else it will be relative positionable.

OK, I just was thinking about absolute positioning.

How about other questions, related to RootPanel and using makePositionable()?
Incompatibility with RootPanel/AbsolutePanel makes bad impression for beginners.
I just drop ExtGWT Button on design canvas and see that it ignores location, but generated code is absolutely correct, it works for standard GWT Button.

sven
21 Jun 2009, 11:22 AM
The problem with automatic setting it is that it wont know which position you need (relative or absolute). I will take a look into it for the next release.