问题
This seems to be a question where the answer is implicit, hence I can't find anything explicit.
Does Google Web Toolkit only support custom layout managers, or a sub-set of the Java layout managers?
For example, is it possible to take a Java Swing application using GroupLayout and get it to work with GWT?
回答1:
GWT layout support is done through subclasses of 'Panel'. Some of them like 'DockPanel' behave a little bit like Swing layouts (BorderLayout) but there's no way you'll ever be able to take Swing code and compile it into GWT.
This is a common mis-understanding when it comes to GWT. It's written in Java solely because Java is statically type and widely supported with world class editors. The fact that it's written in Java has nothing to do with any desire by the GWT team to allow you to port SWT/AWT/Swing to GWT. The web is a different environment to the desktop, and since your code ends up compiled into javascript it would never make sense to take any kind of Java Desktop application and hit the convert button. That's what Applets tried to do many years back...and we all know how that turned out ;)
回答2:
No, GWT doesn't support Layout managers from Swing/AWT. These are not compatible.
Source of incompatibility is that those are totally different technologies with different APIs. Swing/AWT is pixel-based, while GWT renders to HTML. GWT layouts simply output different HTML tags (div/table/inline elements, ...), while Swing/AWT layouts do actually compute position of children components. In GWT, position of children is computed by browser, when they are displayed.
回答3:
Most bottom line issue is that World Wide Web isn't Desktop Application no matter how much you'd want it to be. There's numerous issues involved, these are some which pop into mind:
WWW is stateless, desktop applications aren't. WWW is made stateful usually by cookies, URI parameters and session management and now that we've those for a couple of decades, we've mostly gone over the stateful/stateless issue of WWW.
WWW pages are (nowadays) described with some form of XML and usually CSS, in which the page is described as a tree. Comparing to Desktop Applications, while it's possibly to do nearly the same with XML and just plain component clustering, it just isn't the same. Once again one of the biggest issues is that in DA those components, widgets are stateful by nature on the application level while in WWW you can be truly stateful on the page level at most and even that requires JavaScript/AJAX.
So, direct use of layout managers is a no-go. But, assuming the Web UI Framework you're using allows it, you may create something that behaves quite similarly to layout managers. While I don't know about GWT specifically, I believe that one could do at least a simple layout manager in JSP (or my favorite, Apache Wicket) and make it behave just as the Swing layout managers do.
Note that I really do mean re-creating the whole concept of layout managers here as a set of specialized classes/whatnot, just as Peter Štibraný replied, GWT doesn't support them directly (in fact I haven't heard anything beyond Swing does) and I believe it would be more of an effort to create a wrapped/adapter for Swing Layout Managers instead of just creating your own, properietary ones for WWW.
回答4:
IF you want a Swing Web application, consider AjaxSwing, but be prepared for network latency and consuming server resources. I think as soon as there's libraries for SVG/VML, we'll see more stuff move to the web. If you want to see a JavaScript IDE, check out Lively Kernel from Sun Labs. Have people tried porting Swing to GWT? It seems evident that there's AjaxSwing that a lot of Swing Could be ported to GWT, just perhaps not the Java2D stuff. Probably some smart company will figure out how to convert Swing to web client technology.
来源:https://stackoverflow.com/questions/763250/how-much-support-does-gwt-have-for-java-layout-managers