I'm fighting to understand the weird behavior of GWT Layout Panels. I'm wondering how GWT translate Layout logic into javascript and html. sometimes we don't get the expected Layout . something under the cover is done by GWT compiler.
the GWT documentation is not clear enough on how Layout is performed under the cover.
is there some good books or tutorials that explains well the GWT Layout issues?
thanks.
I don't know about good books or tutorials but here's a little information that may be helpful.
First, as you may know there's a big difference between the FooPanels and the FooLayoutPanels. These are two different sets of panels that are based on different layout mechanisms. The Layout Panels are the new stuff that seems to be suited better for layouts that have hard-coded sizes, Google Wave style. The older FooPanels (VerticalPanel, etc.) are based on HTML tables mostly.
FlowPanel - this is simply something that outputs your widgets as successive HTML elements in a single DIV. As documented: "A panel that formats its child widgets using the default HTML layout behavior".
DockLayoutPanel - Looking at the code shows that it hard-codes the sizes of the different regions according to what you specify in the children (north, east, etc.)
Finally - my experience has led me to abandon all usage of the Layout Panel system and rely only on HTML and CSS wherever I can. This means using HTMLPanel + UiBinder mostly and sometimes FlowPanel, rarely also some of the other panels.
Trying to understand and battle the Layout Panel system to do things that are not the "default case" was a waste of time. I'm not saying it's the best thing to do, but I just couldn't get the kind of control I wanted without this - especially with regard to elements that should automatically expand vertically. If you haven't already, take note of this from the GWT documentation about Layout Panels:
The panels described above are best used for defining your application's outer structure — that is, the parts that are the least "document-like". You should continue to use basic widgets and HTML structure for those parts for which the HTML/CSS layout algorithm works well. In particular, consider using UiBinder templates to directly use HTML wherever that makes sense.
Related
I don't know if this is the right place to ask this question but I figured I might as well try to get an answer here.
My problem is the following: I'm a huge fan of Bootstrap and all there components so I'm genreally using them in every project im working on. So when I'm using container and container-fluid with different row's in between for sertain content-elements I haven't figured out a way to implement this inside the backend in an user-friendly way.
The way I used to do it was simply use the Grid Elements Extension to simply create containers, row's and col's and implement those within each other in the backend. Works fine, but its a whole lot of work for the user of the site to create content. I don't know if my explenation was clear, english isn't my first language and I don't know how to describe it in another way, but here's a picture of what I'm trying to say:
As you can see there are a lot of elements nested within each other so the user or admin has to actually "know" how bootstrap works to edit content without destroying the layout.
Is there any other way I can achive full flexibility for the content, e.g. a bunch of container's within a container-fluid as a wrapper and another bunch of cols's as children of the container?
I've tried to work with Mask, which seemed to be the solution at the beginning, but in the end I had to create one mask object for every possible way an element could be loaded, so there goes this option..
Does anyone else have this kind of "problem" or is there a simple (or hard, idc) solution I can use?
Thank you guys :)
I understand your "problem". My opinion: As soon as you have a page layout with multiple containers (container / container-fluid) and a flexible grid layout, I guess there is no better way without restricting flexibility or have some dirty logic / code. In some (minor) cases, you can help yourself with layout classes (DB field "layout") and some logic in fluid + a viewhelper to calculate the grid columns (e.g. imagegallery, where you can set the columns in backend and calculate the columns in frontend). But in my opinion, this is the most flexible way.
There are some people who solve this with new content elements and inline relation to its content elements. But IMHO this is more confusing for editors to see a grid layout in the backend and the possibility to flexible add content elements via content element to the container / column of choice.
A small, but effective useful helper for editors is to colorize your grid elements in the backend to help the editor to recognize different grids.
In my experience, editors can handle nested grids better than searching for multiple dropdowns in elements to understand grids.
Offtopic: editors survived templavoila, they will understand grids :-)
according to https://developers.google.com/web-toolkit/doc/latest/DevGuideUiPanels#Standards I 'm not suppose to use DockPanel, VerticalPanel, HorizontalPanel. But Those are the only panels that support hasverticalalignment and hashorizontalalignment. How am I suppose to align the widgets if I want to conform to the standards mode? Or should I keep the project in its current form using VericalPanel and HorizontalPanel, and ignore the warning eclipse gives me:
[INFO] [project] - GWT no longer supports Quirks Mode
(document.compatMode=' BackCompat').Make sure your application's
host HTML page has a Standards Mode (document.compatMode='
CSS1Compat') doctype,e.g. by using <!doctype html> at the
start of your application's HTML page.To continue using this
unsupported rendering mode and risk layout problems, suppress this
message by addingthe following line to your*.gwt.xml module
file: <extend-configuration-property
name="document.compatMode" value="BackCompat"/>
P.S.: I work in uibinder
Using tables for layouts is considered a bad practice by most UI experts. These layouts are rigid - they don't adjust well with the size of their contents.
You can build any layout you want without using these panels. Horizontal alignment is the easiest one: you simply add a CSS rule "text-align: center" (left, right) to the parent widget. For more interesting effects you can use "float: left" or "float: right". In some rare cases you may event want to use absolute positioning ("position: absolute", "left: 20px"; "top: 20px").
Vertical alignment is a little trickier, but generally you want your content to flow from top to the bottom. You can manage vertical positioning by using top and bottom margins or setting the line heights.
You can find many great resources on building fluid layouts on the Internet. Most suggested html and CSS solutions can be used with GWT, and Ui:Binder is a very convenien way to do so. You can also search StackOverflow for layout solutions to any problem you face.
i'm new to j2me. how to set form elements (text field ,text box) width,font,alignment and other Gui related properties.
i tried to find solution for setting form background but no success. can you guide me
Firstly, J2ME is a very limited framework.
As far as I can remember if you are just using an item from the basic javax.microedition.lcdui package there is very limited styling available. It allows you to give directives on how to lay the item out on the screen and what the item's appearance mode will be.
An Item is not responsible for where it is placed and is down to the Screens layout management algorithm to place your item on the Screen. For example, the way Items are laid out on Forms and Lists differ based upon how the layout management works.
You can create your own customs items by extending CustomItem and implementing and overriding various functions to get the desired visual effect. This however is a lot of work
and the end result is not always very pleasing. You could also do the same by extending the Form class and overriding the paint methods to get your disered visual effect.
The best way to have control over form elements is to use one of the Widget like frameworks that exist and are built upon these basic J2ME classes. For example LWUIT and J2ME Polish allow you to style items in a very similar manner and layout Items using a CSS box inspired manner.
Although I have no used LWUIT so cannot vouch for it.
In our project we decided to try to design our UIs with UIBinder instead of doing everything in Java mixing GWT widgets and logic. We found out how much prettier they look panels, buttons and such from scratch, which saves a lot of time especially for presenting a demo. However, when we use number box widgets, like IntegerBox or DoubleBox, they don't appear as pretty as TextBoxes, they are like plain HTML boxes, thus quite ugly in contrast with the rest of the widgets. We did some Google search but nothing came up about this topic.
Is there any trick to accomplish this, to use GWT native number boxes with UIBinder and to appear in the pretty style? Or maybe we should just use TextBoxes for everything and write our own wrappers for setText-getText and parse the values.
This is really important as we have to make client-side calculations with input numbers before sending data back to the server.
UIBinder is not in any way responsible for things looking "pretty", it only generates Java code, the same kind of code that you were coding by hand previously. If things look "prettier", it's likely because you <inherits>-ed a theme in your gwt.xml.
Contrary to TextBox though, IntegerBox and DoubleBox don't have an associated hard-coded style name. If you want to have them style the same as every TextBox, you can then simply addStyleName("gwt-TextBox") to them (the hard-coded style name of the TextBox widget), or in your ui.xml: <g:IntegerBox addStyleNames="gwt-TextBox" … (note the plural here; this is documented in UIObject's javadoc).
What is the difference between Stackpanel and Stacklayoutpanel?
According to the Dev Guide, StackPanel is deprecated and you should use StackLayoutPanel. Basically StackPanel works only in quirks mode, while StackLayoutPanel works only in standards mode, as well as being rooted on the RootLayoutPanel, not the RootPanel.
The LayoutPanels are a newer collection of panels that have much more predictable behavior across browsers. When given a choice, prefer anything based on the Layout system.
This is waaaaay oversimplified, but on a general level, all of the layout panels are more "div" like, vs. the original panels being organized in tables.
So, when you want to do predictable stuff across disparate screen sizes, etc., the layout stuff does what you've come to expect. So definitely use them over all else. In fact, if you're trying to use GWT for the ease of writing in Java and ignoring web design, use as many FlowPanels with css as possible.