Hybrid View
-
31 Aug 2009 9:16 AM #1
RowLayout(Orientation.HORIZONTAL) not calculating height correctly
RowLayout(Orientation.HORIZONTAL) not calculating height correctly
The following should show a horizontal array of buttons, but for some reason the height ends up being zero. I think RowLayout (horizontal) may have a bug so that it only renders right (nonzero height) if you manually set the height? Is this right or am I missing something?
HTML Code:public class HorizontalButtonBar extends LayoutContainer { @Override protected void onAfterLayout() { super.onAfterLayout(); System.out.println("Debug Height = "+getHeight()); } public HorizontalButtonBar(Button[] buttons) { super(new RowLayout(Orientation.HORIZONTAL)); for (Button button : buttons) { add(button, new RowData(-1,-1, new Margins(10,10,10,10))); } } }
-
31 Aug 2009 9:21 AM #2
I guess you are not sizing your HorizontalButtonBar.
-
31 Aug 2009 11:10 AM #3
Shouldn't it work just like this works (below).... which works fine.
HorizontalPanel seems to realize that my buttons are not all zero in size, and therefore it looks fine. However RowLayout seems to forget that the content (my buttons) may have some size. I realize GXT is not trying to model an API like Swing where there there *is* always a 'preferredSize', but nonetheless it should work in a case as simple as this. its' just a row of buttons! I can't set the height, because I want to be 'font independent' in my code. Hard coding sizes (as any Swing or SWT user knows) is *extremely* bad practice, nearly 100% of the time.HTML Code:[LEFT]public class HorizontalButtonBar extends HorizontalPanel { public HorizontalButtonBar(Button[] buttons) { setSpacing(10); for (Button button : buttons) { add(button); }[/LEFT] }
-
31 Aug 2009 12:09 PM #4
workaround
workaround
here's what I did as a workaround...
it is ugly that I had to override onAfterLayout...but at least it works.HTML Code:public class HorizontalButtonBar extends LayoutContainer { private Button[] buttons; private static final BUTTON_BAR_SPACING = 10 @Override protected void onAfterLayout() { super.onAfterLayout(); if (buttons.length > 0) { setHeight(buttons[0].getHeight()+BUTTON_BAR_SPACING*2); } } public HorizontalButtonBar(Button[] buttons) { super(new RowLayout(Orientation.HORIZONTAL)); this.buttons = buttons; for (Button button : buttons) { add(button, new RowData(-1,-1, new Margins(BUTTON_BAR_SPACING, BUTTON_BAR_SPACING, BUTTON_BAR_SPACING, 0))); } } }
This renders a horizontal array of buttons with *no space* at the left of the letftmost button which is what I wanted!
-
1 Sep 2009 5:09 AM #5
thanks for your workaround.
im just now also getting grey hair with the layout: RowLayout / HBoxLayout / VBoxLayout.
in the API there is written that this layout not calculate the height and you have to set it by yourself or from the outer layout - but im not getting this working without setting some height like you writing this.
i need some widgets positioned horizontaly but i need the size of the H-Panel as the max size of the widgets.This forum needs your help: you got hints from the community and now you have fixed your code? dont just reply with "now its fixed" or "i found the error"! please take the time to post also an detailed answer with the working code.
GreaseMonkey Script for a GXT-only Forum: it hides ExtJs here: New Posts • Search Results • Advanced Search form • Category overview http://www.extjs.com/forum/showthrea...041#post410041
-
8 Sep 2009 10:10 AM #6
For what it's worth, I've noticed the exact same problem - that RowLayout(horizontal) doesn't automatically calculate its height, whereas RowLayout(vertical) does. Sometimes I need to lay out a bunch of widgets horizontally, and I want to put them in a container whose height is automatically determined based on the contained widgets. I don't want to set a specific height on the container, because that's not maintainable when I put different widgets in it. This seems like a bug to me, or at least a painful limitation.
-- Joe


Reply With Quote