(a) I use a layout panel for page structure, an it resizes by itself as the browser window resizes;
(b) I use fluid HTML/CSS layouts for inside content, relying on the browser to reflow the content as the page size or the content size changes.
There are many good resources on building fluid layouts in HTML/CSS, and all of the suggested techniques can and should be used when using GWT.
Maybe if you can give a specific example of a problem you face, we can suggest a solution.
Maybe if you can give a specific example of a problem you face, we can suggest a solution.
How about using nested LayoutPanels? Or if you don't want to use LayoutPanels all the way but need resizing in one of the inner widget you could wrap it in a http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/ResizeLayoutPanel.html.
So there are two questions:
- Do I really have to call the widget's onResize manually, after setting its size using the LayoutPanel's methods?
- How can I schedule this call, so that the widget's onResize is called after its parent has been resized?
Magnus
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/2uqreZcZNCwJ.
Jens is right: all you need is a simple FlowPanel with a Label and a button inside. Set the button style to "float: right", set its width (which, I assume, is constant), and add a right margin to your label which is wider than the button. That's it. Your generated code will be 10 times smaller (layout panels produce a lot of HTML), and your pages will reflow much faster.
You don't need to worry about the height: a FlowPanel will expand automatically to accommodate its contents. If you want, you can fix its height, or you can use min-height and/or max-height CSS rules. You can set a width of the FlowPanel in pixels or as percentage of its parent's width, or you can let it expand with the content up to a specified maximum. You can allow the content to wrap inside the widget, or you can force it to show ellipsis when the label gets too long, or you can force a scrollbar, etc. There are a lot of options available to you in CSS. I use layout panels only for page structure, and I never use HorizontalPanel or VerticalPanel - they offer nothing that cannot be easily done with FlowPanels and CSS, while they are less flexible as you have discovered.
My advice: when building a layout, forget about widgets. Think how you can do it in pure HTML/CSS, ideally without any <table> elements. Once you do it, the choice of widgets becomes obvious.
you can drag the vertical splitter to change the size of the result and the label <div> fills all the space while the button is float:right. No need to use any onResize() JavaScript as the browser takes care of the size. Maybe you can omit the div that clears the float:right.You should use as much CSS as you can, so you don't have to worry about resizing your widgets. Let the browser do it.
How about using nested LayoutPanels? Or if you don't want to use LayoutPanels all the way but need resizing in one of the inner widget you could wrap it in a http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/ResizeLayoutPanel.html.
By the way, implements RequiresResize is unnecessary in your code, because you init your Composite as a LayoutPanel, and it already has all the functionality that you need.
There are many great GWT widgets that insulate you from major browser issues, especially LayoutPanel, PopupPanel, DialogBox, DataGrid. But it's too expensive to try and figure out solutions for minor issues, so they still remain.
If fact, I think that trying to be fully cross-browser hurts GWT. GWT's popup panel is a table where every rounded corner is its own cell, even though all modern browsers support border-radius rules. I would love to see GWT drop support for IE
There are many great GWT widgets that insulate you from major browser issues, especially LayoutPanel, PopupPanel, DialogBox, DataGrid. But it's too expensive to try and figure out solutions for minor issues, so they still remain.
For example, the solution posted by Jens works perfectly in isolation, but when I put it into a LayoutPanel it didn't work at all.
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style>
.layer {
background-color: red;
}
.label {
background-color: orange;
margin-right: 70px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.button {
width: 50px;
float: right;
}
.clear {
clear: right;
}
</ui:style>
<g:LayoutPanel>
<g:layer top="20" bottom="20" left="20" width="200">
<g:HTMLPanel styleName="{style.layer}">
LEFT
</g:HTMLPanel>
</g:layer>
<g:layer top="20" height="60" left="240" right="20">
<g:HTMLPanel styleName="{style.layer}">
<div>
<g:Button addStyleNames="{style.button}">></g:Button>
<g:Label addStyleNames="{style.label}">Label Label Label</g:Label>
<div class="{style.clear}"></div>
</div>
<div>
<g:Button addStyleNames="{style.button}">></g:Button>
<g:Label addStyleNames="{style.label}">Label Label Label</g:Label>
<div class="{style.clear}"></div>
</div>
</g:HTMLPanel>
</g:layer>
<g:layer top="100" bottom="20" left="240" right="20">
<g:HTMLPanel styleName="{style.layer}">
CENTER
</g:HTMLPanel>
</g:layer>
</g:LayoutPanel>
</ui:UiBinder>
the only empty DIV I see is the label, and it's empty because the label does not contain text.
Do you agree to the statement posted in this thread that the GWT's layout panels should be used for the overall page layout (defining the main areas of a page) and that the small layouts (widgets and so on) should be positioned with CSS?
Maybe you misunderstood my posting: I also said that GWT compiles to HTML and CSS. But it produces different compilations for different browsers. In contrast, everything you put directly into the element attributes will go unchanged into the client.
However, even Google states that in strict mode many panels do not work as expected, e. g. HorizontalPanel, which should be replaced by a FlowPanel where all children should float to the left (which does'nt work in some cases).
The goal was "predictive layout", but it seems to be more like "trial and error", at least in some cases.