GWT DockLayoutPanel with browser determining size of some subpanels? - gwt

It looks like you have to specify absolute sizes of all but one subpanel. For example, from the GWT docs:
DockLayoutPanel p = new DockLayoutPanel(Unit.EM);
p.addNorth(new HTML("header"), 2);
p.addSouth(new HTML("footer"), 2);
p.addWest(new HTML("navigation"), 10);
p.add(new HTML(content));
But I want the north panel sized by the browser. I put some text or buttons in it and I don't know exactly what size it will be, I just know it is relatively thin and at the top of the page. And I want the content to take up the rest of the space, but no more, so there are no browser scroll bars. Is there a way to handle this with these newer layout panels?
Right now I'm using the older panels, and I have a handler attached with Window.addResizeHandler, which sets the height of the main content area so that everything fits within Window.getClientHeight
Update:
Thomas suggested a DockLayoutPanel inside a HeaderPanel, but this is not working for me:
<g:HeaderPanel>
<g:Label>Header top</g:Label>
<g:DockLayoutPanel unit='PX'>
<g:west size='300'>
<g:Label>West</g:Label>
</g:west>
<g:center>
<g:Label>Center</g:Label>
</g:center>
</g:DockLayoutPanel>
</g:HeaderPanel>
"Header top" is there, the rest invisible. It looks like inner divs are getting 0 height.

You should put a DockLayoutPanel (for the west and center regions, possibly the south one too if you don't want it to use its natural height) in a HeaderPanel (for the natural sizing of the north region)

Related

Resizing Panels in proportion to form

I am developing a Delphi game for my (grade 10) PAT.
I am using an image as a grid for my game and placing individual panels in each grid because I do not know how to use string grids as it's my first year with Delphi. When I place the panels perfectly in each grid of the image and run my code everything looks normal until I go full screen,then all the panels are in each grid but the size is not in proportion with the image as I placed it before.
A solution would be much appreciated.
Thanks in advance.
Use a TGridPanel in place of your image. Each panel goes into one cell of the grid, and with the column widths and row heights set as a percentage (which is the default), and both the grid and the panels in the grid having Align set to alClient, the cells, and therefore the panels, will adjust their size proportional to the entire form.

Need GWT SplitLayoutPanel to have max size, dragging is very jumpy

Is there a good way to set the max size for a child of a SplitLayoutPanel? Right now I override its onResize method and call a JSNI function to set the right or width style properties of the parent div of the center panel's div, the right panel's div and the splitter panel's div, if the right/east panel is over 400px wide.
I noticed the splitter and the right panel's size don't even follow the mouse cursor and oscillate wildly between about 4/5 and 2/5 as wide as they should be based on where the mouse pointer currently is.
I have debug in eclipse and tried running it without eclipse and it's the same. I am calling super.onResize(), as well.
If I am understanding your problem correctly, you want to have a SplitLayoutPanel to occupy maximum space of the parent element. For this you can use the percentage property of width like,
SplitLayoutPanel slp = new SplitLayoutPanel();
slp.setWidth( "100%" );
And in the next step you want to add child element into the SplitLayoutPanel and it should occupy maximum area. Then set each child width to 100%
Widget child = // Instantiate any type of widget
child.setWidth( "100%" );
slp.add // Use proper add method and add the child to SplitLayoutPanel
I did not understand what did you mean by dragging is very jumpy. Did you mean Splitter size is too small that you cannot find the splitter. If thas the case, you can increase the splitter size by passing it in the constructor like
int splitter_size_in_pixels = 5;
SplitLayoutPanel slp = new SplitLayoutPanel( splitter_size_in_pixels );
I noticed the splitter and the right panel's size don't even follow the mouse cursor and oscillate wildly between about 4/5 and 2/5 as wide as they should be based on where the mouse pointer currently is.
I too saw jerky movement when dragging the splitter. My south pane contained a vertical panel which contained a label and a table. The fix was to set the VerticalPanel height="100%" . I have appended the uibinder code.
HTH
Julian
<g:SplitLayoutPanel styleName="gwt-SplitLayoutPanelTtc" ui:field="splitLayoutPanel">
<g:north size="40">
...
</g:north>
<g:west size="200">
...
</g:west>
<g:south size="500">
<g:VerticalPanel height="100%" width="100%">
<g:Label ui:field="tableTitle" styleName="tableTitle"></g:Label>
<g:Grid ui:field="table" styleName="gwt-Grid"></g:Grid>
</g:VerticalPanel>
</g:south>
<g:center>
...
</g:center>
</g:SplitLayoutPanel>
You can fix the jerky/jumpy movements by adding intermediate ResizeLayoutPanels.
MyComposite.ui.xml :
<!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"
xmlns:my="urn:import:my.custom.package.client">
<g:SplitLayoutPanel ui:field="splitLayoutPanel">
<g:west size="250">
<g:ResizeLayoutPanel ui:field="leftMenuOuterPanel">
<my:MenuWidget ui:field="menuWidget" />
</g:ResizeLayoutPanel>
</g:west>
<g:center>
<g:ResizeLayoutPanel ui:field="centerOuterPanel">
<my:AwesomeWidget ui:field="centerWidget" />
</g:ResizeLayoutPanel>
</g:center>
</g:SplitLayoutPanel>
</ui:UiBinder>
thanks to OlivierH answer

GWT Datagrid horizontal scrollbar doesn't appear

i have a small screen and i want the horizontal scrollbar on datagrid to appear automatically.
i've used:
dataGrid.setMinimumTableWidth(1500, Unit.PX);
this sets the width both the scrollbar still not appear
any tip?
I had a similar problem. When using DatGrid make sure you place it within a ResizeLayoutPanel. Set the height of the panel to xxx PX and the width to a yyy %. Then for the DataGrid just set width to 100%. Column widths units can be EM, PCT, or PX. In fact do not set all column widths to total 100%, otherwise you'll get funky display issues. Hope this helps.
So I tested out this code, both scrollbars show.
<g:ResizeLayoutPanel height="480px" width="760px">
<c:DataGrid width="100%" addStyleNames='{style.cellTable}' ui:field="testResultTable"/>
</g:ResizeLayoutPanel>

GWT widget on bottom without knowing height/size

I want to have a two widgets to stack up
X
Y
I want Y to take up as much height as it needs (its static in size, roughly 50px depending on browser font, etc) and remain affixed to the bottom of the screen, and X to take the rest of the vertical space.
X happens to be a scrollpanel with VerticalPanel and more inside, Y is a Grid and I've tried putting them in various containers, but they all seem to want a size for Y (ie. DockLayoutPanel & LayoutPanel). If I specify a size for Y it ends up with white space at the bottom on one browser or another. Any advice?
It's just not possible in HTML/CSS. If you absolutely cannot know the height of Y in advance, the way around it would be to:
Attach this widget somewhere off-screen
Measure it's height using yWidget.getOffsetHeight()
Remove it
Add it to your LayoutPanel and setting the 'bottom' coordinate to 0 and 'height' to the measured height.

Styling GWT's DockLayoutPanel

I am trying to create a DockLayoutPanel using GWT. It should occupy the complete screen.
DockLayoutPanel dockPanel = new DockLayoutPanel(Unit.EM);
dockPanel.addSouth(new HTML("South"), 2);
dockPanel.addNorth(new HTML("North"), 2);
dockPanel.addEast(new HTML("Easat"), 2);
dockPanel.addWest(new HTML("West"), 2);
dockPanel.add(new HTML("Center"));
RootLayoutPanel.get().add(dockPanel);
I believe that the second parameter to the add methods is the width of the respective panels. How does the layout decide the height of the panel?
How can I style the layout, like add border to the panels, spacing between the panels, add panel headings in-line with the border?
Should the panel background colors be set using CSS, or is there a way to do so from java?
Can I make these panels as drag and drop panels?
1) The second parameter is really the size of the panel. It will be the width or the height, depending of the layout position. Use Unit.PX or Unit.PC for a clearer result, the EM unit maybe confusing at the beginning.
2) Use CSS styles.
3) Again, use CSS
4) It's not possible using GWT alone. Take a look to the GWT-Mosaic project. Specially to the "Drag & Drop Column/Row Layout": http://mosaic.analytical-labs.com/#CwDNDColumnRowLayout
1) The height and such are determined using normal HTML layout rules. The height and width of the panel is just the height and width of the containing div.
2) Style it using CSS just as you would any other div. UiBinder makes this pretty easy.
3) Yes, use CSS. You can call getElement() and getStyle() if you want to manipulate it directly or addStyleName() to add a CSS class. Regardless, UiBinder is probably the better bet than doing it in Java.
4) AFAIK, there's no way to do this out of the box. You'll have to write some code to handle that. SplitLayoutPanel will let you change the sizes of the panels, but not the positions.