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?
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 ;)
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.
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.
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.
Related
Technically it has been "possible" to create a javafx/groovyfx based griffon application for quite a while.
How does swing compare to javafx nowadays ?
Can the latter be generally recommended for a fresh application without legacy baggage ?
Any gotchas to watch out for ?
How is the relationship griffon + javafx/groovyfx doing in general ?
JavaFX is the successor to Swing, and has many advantages over Swing, including:
A scene graph in which all nodes (e.g. UI components, shapes, images, containers) reside. This provides the ability to manipulate the properties of any node in UI with the result of affecting its contained nodes. For example, a Group containing some images may be rotated as a unit by applying a rotate transformation on the Group. Compare this to Swing, in which the UI is comprised of two separate worlds: UI Components and Java2D.
The WebView node is a WebKit port that that lets you embed a web browser in the scene graph.
CSS may be used for skinning the UI
FXML may be used to define the UI separately from the application logic. SceneBuilder, whose output is FXML, is a tool for drawing a UI.
There are currently some features that Swing developers mention that they miss, but you can take a look at the OpenJFX project http://openjdk.java.net/projects/openjfx/ and participate in this very active community to influence and contribute to future versions of JavaFX.
You may be interested in a technology position paper written by Björn Müller of CaptainCasa.com entitled "Why we use JavaFX" that discusses their architecture, including their decision to move from Swing to JavaFX
http://captaincasa.blogspot.com/2013/01/why-we-use-javafx-paper.html
I hope this helps, and welcome you to check out the JavaFX Community site at javafxcommunity dot com to see the latest blog posts from JavaFX developers.
Regards,
James Weaver
Oracle Java Technology Ambassador
I can recommend use javafx instead of swing. It's easy to learn and the apps look much better. I've made several applications using javafx with griffon at my work and I haven't been problems.
Why, Where, and How JavaFX Makes Sense
http://www.oracle.com/technetwork/articles/java/casa-1919152.html
Im working on coding a WYSIWYG document designer. The basic intent of this designer is to be capable of both reading(loading) and creating multiple documents written in a variety of templating languages (ZPL, XSL-FO etc).
Now for the sake of building a WYSIWYG designer, i plan to have an elegant UI which the user can play around with to create/edit the document.
The compulsory needs of the UI is that --
The UI should be such that the user must be able to pick or
choose elements and be able to drop them off on the UI. Once
dropped, the position of the elements should be capable of allowing
repositioning.
The UI must associate the spatial postioning of elements to the
element's metadata (say, x coordinate,y coordinate, height ,width
etc).
The UI must be capable of seamlessly passing on the elements and
their spatial positions to a backend module,written in Java, that
would wither edit or create the document in the specified templating
language.
Im having trouble in deciding what to implement the UI in. I tried Swing and found it to be not great(was pretty rigid for my needs). Any suggestions with regard to what can be used to build the UI described above would be of immense help.
Your underpinnings options are pretty much Swing or SWT.
Not sure what you mean by "rigid"; Swing is a pretty good GUI framework architecturally, although some prefer SWT. Not sure how JavaFX will end up, but it has some nice features.
XUI layers on top. Or take the Griffon approach, although I'm not sure it's a great fit for the type of application you're working on. Or use Groovy/JRuby/etc. to make many aspects of working with Swing/etc. less painful.
IIRC there are Java bindings for QT as well, if the QT licensing works for you.
Perhaps you'll be better served by some rich client platform (RCP) like Eclipse or NetBeans. Both are probably best known as IDEs, but the IDEs are actually built on top of the respective platforms. Using an RCP will take a lot of responsibility out of your hands. Existing plugins/modules can be made to interoperate with your code and facilities such as perspectives (Eclipse) or rearranging panels are accounted for.
Like Dave Newton hinted at, JavaFX could also be a candidate. JavaFX 2.0 is now out and no longer requires the scripting language used in 1.0, instead opting for a Java API that'll feel more natural to experienced Java developers. And it can be used within Swing.
Swing provides the basic building blocks for any GUI application but what about a higher level take on building GUI applications?
I'm not asking about the many arbitrary libraries that provide yet more wizzy variants on various visual components.
I'm talking about the missing pieces that everyone ends up building themselves whenever they create anything other than a trivial GUI application.
I.e. the framework that the application specific logic builds on.
E.g. handling data binding, application lifecycle issues or supporting common things like building forms.
If we were talking about persistence you could say that anyone can code up their own persistence layer using the javax.sql or java.io classes - however most people would rather use something like Hibernate.
So, just as someone asking about persistence libraries probably isn't looking for variants on ObjectOutputStream, I am not looking for variants on some JComponent subclass or other.
I think this is a fair Stackoverflow question as, unlike areas like persistence, a clear consensus on the answer is not easy to determine using Google.
Rather than a grab bag of random libraries perhaps people could answer in terms of what GUI issues are not immediately addressed by Swing and what libraries they feel best fill these gap?
I asked a similar question to this last week and it was closed - I've tried to phrase this such that this won't also be closed. If you feel inclined to close it perhaps you might consider making it community wiki instead?
Here are some essential libraries:
JGoodies - http://www.jgoodies.com/. This provides some nice layout tools (FormLayout) as well as common builders and databinding tools
SwingLabs - http://www.swinglabs.org/. This provides many common components you likely may need to use that are not part of standard swing.
Swing Application Framework - https://appframework.dev.java.net/ (already mentioned by jluzwick)
Groovy SwingBuilder - http://groovy.codehaus.org/Swing+Builder. This provides for easier building of GUIs by using a logical, hierarchical scripting-like language for building GUIs. It also has native support for some databinding.
Could you be referring to something like this?
https://appframework.dev.java.net/
This was integrated with Netbeans at one point and I don't think the development has continued, but this framework greatly helped me in creating a much more involved application with java.
EDIT:
It seems these projects are derivations of the former I mentioned that are actively in development:
http://kenai.com/projects/bsaf/pages/Home
http://kenai.com/projects/guts/pages/Home
JGoodies Bindings is great if you want to have a well-architected program.
NetBeans Platform (RCP) I really want to try. It's really the only viable Swing frameworks because ...
Swing Application Framework is very lacking and is not actively in development anymore.
MiGLayout is my favorite layout manager for cases where I used to use GridBagLayout (long time ago) and JGoodies form layout. Also, I dislike GroupLayout.
Have look at the NetBeans Platform (Swing based RCP)
I am no artist/designer so usually my GUIs well, you know... I've tinkered a bit with GWT and I was able to get sensible results but I feel I have used contrived ways of getting those results.
If the community feels this question could help: please put one recommendation per answer.
We identified the following high-level best practices for GWT 1.6/1.7 (just after 3 months of research and development):
Use design patterns (MVC/MVP, Command for GWT-RPC, Composite for widget composition, Observer for event bus, etc.);
Isolate application logic with MVP by abstracting out widget classes and views using presenter display interface and GWT characteristic interfaces (such as HasValue, HasText, etc.);
Use dependency injection with gin on a client and Guice on a server (or stick with existing server framework like Spring);
Use GWT Composite in combination with HTMLPanel to drive your views with html, css and MVP;
Use mock testing based on isolation of application logic with MVP;
Implement Event Bus with GWT HandlerManager;
Use GWT modules to effectively optimize code compilation;
Use client, shared, and server packages when organizing GWT modules;
We have developed a large HR portal with GWT. The look and feel of this application can be customized for different deployments. To do this we use fragments of HTML to generate parts of the GUI i.e. bits of HTML are sent to the client in DTOs and then stuffed into HTML widgets. This approach works well for mastheads, logos, menus and so on.
Other things (e.g. capture forms) are generated using normal GWT code.
We use "pages" (different history tokens identifying where you are) as this makes it possible for users to use bookmarks in a meaningful way. We also generate links to different parts of our system in emails and so on.
Our application is composed of a lot of "higher level" widgets we call "Portlets" arranged into "pages" defined in XML. Again this makes it possible to customize the functionality for a given installation.
All this is done using a framework (GWT Portlets) that we have published as open source.
The best practice is to do everything from Java, so your HTML only acts as a placeholder. Yes I hate to say this, but if you're still messing around with the HTML it only makes your life more miserable.
If you still have the only web mindset, which is separating webapps into several html pages, throw that away, get the building the desktop app (that run on the browser) mindset. Think of building swing apps.
If you need to style the GWT components, override the GWT's css classes in your own CSS.
The last best practice is to decouple your application with the MVP pattern. The reason is because you can basically write the whole application in one Java class, which of course can lead you to maintenance hell, and problems if you are working with several peers.
This question was originary in my head as "Can I use AWT controls in a Servlet?", which will show all my ignorance on the subject.
I am new to JAVA technologies but after a bit of reading, I seem to understand AWT controls directly hook up the OS GUI elements so there is no way to use or extend JPanels, JButtons and so forth in a Servlet to be injected in a JSP and let the browser render those controls (an alternative could probably be embedding an applet in a JSP but I don't wanna do that).
I am looking for a way of building custom re-usable web controls using JSPs and Servlets.
How is this usually done and can you provide some samples/links?
EDIT: This is part of a test run I am giving to the Google Application Engine - so it would probably make sense for me to explore the Google Web Toolkit - any pointers in that directions would be appreciated as well.
Any help appreciated!
AWT is the OS-specific part of UI rendering on desktop, not on the Web side of things in which JSP, Servlets etc. live. A bit more specifically, things like Swing (which has those JPanels, JButtons and so on you mentioned as UI components) and SWT are currently based on AWT and work on top of it to render the UI and allow it to work as expected.
Unfortunately all this means you can't use AWT based components on Web pages since, well, Web pages are (usually) platform agnostic in the sense that they don't get to decide exactly how parts of the UI are rendered, there's just a pile of markup which is treated as a sort of plea to the Web browser to do things the Web designer hopes for without 100% quarantee that the end result will be what the designer wanted.
There's been a lot of reinventing the wheel to achieve Swing/AWT kind of UI creation on the Java's Web side since it's a clever model, like you seem to already know Google Web Toolkit tries to do its part to make Web seem more like a desktop application while in reality it merely automates the needed JavaScript Ajax underneath to make the web page behave as if it was a desktop application. One another framework for this is Tapestry which I haven't personally used but some think it's a decent choice too.
And then there's of course my personal favorite Apache Wicket which allows you to have a true separation between Java code and markup and it behaves quite similarly to Swing UI code too! In fact there's a whole bunch of name collisions with Swing's UI component classes for the most simple things. Assuming you're any familiar with coding a desktop application UI I strongly recommend Wicket, it abstract away the boring and tedious parts (Servlets, URL resolving, page bookmarkability, security...) and replaces them with an event-driven model similar (but not equal) to Swing's EDT which is where the desktop UI magic would normally happen.
While this is going completely away from what you're looking for, with Wicket you can create such a set of POJO Web components that you can reuse them just about anywhere and thus get what you asked for. A word of warning though, Wicket assumes you really know how to code with Java and some laughably easy things may be tedious at first but in the end you should be quite happy with what you got.
In JSP you are probably looking for Custom Tags. Custom Tags are ways to create re-usable code components to be used in the display of JSP pages. There are some very nice ones out there such as those found in the struts2 framework or the display tags library.
But you can write your own or extend the existing ones with new functionality.