• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SwingBuilder not as easy at it looked - a problem with layout

 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am a Java developer and have done a fair share of GUI application building in Java. I am new to Groovy, and, quite frankly, I am confused over a few points. Firstly a gentle rant - but there is a point to it because it involves my first question ... while Java has - in my opinion mistakenly, taken on the overly complex generics tack on in the effort to catch every possible error it can in the compile step, Groovy seems to have gone in the entirely opposite direction and made it not only possible, but extremely likely that a clean compile will not run. Why do I say this? Because I am trying to build a very simple GUI using SwingBuilder in the Groovy/Grails Tools Suite, and I constantly get clean compiles that fail on execution.

So my first question is ... how can this be that I am getting the clean compile and then the errors at runtime are so basic; like: "No class found CENTER"?

My next question is that I have the following code. And of all the constrains for Component placement, only the JButton.CENTER is honored. All the others are simply ignored. The top 'apanel' won't display unless I comment out all the code for bpanel. I've tried various other derivations for placement of Components and none work - some compile and error at runtime and some don't error at all - like these - but are not honored. Here is the code. Thank you very much in advance for any help. Also, for those that do GUI work in Groovy, do you use SwingBuilder, or do you code as you would in Java?


 
author
Posts: 47
VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill,

You almost got it working. The problem you're facing is that the main contentPane (the component used by the JFrame to hold its children) has a FlowLayout as its default layout. You must apply a BorderLayout to this contentPane. Also, the constraints set on both panels are actually not set on the panels. Finally, the print callback intended for the button click event is never assigned to the button.

Have a look at the following snippet and notice the small differences:



Cheers,
Andres
 
Bill Johnston
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Andres,

Thank you for answering. In the interim I have gotten it to work. The FlowLayout was not the problem, as Borderlayout is the default LayoutManager for a JFrame's ContentPane. Rather, it seems that the original way I did it was to place the BorderLayout constraint inside each Panel. I amended the code this way:



I see that the way you did it is similar but different. Part of what I find difficult in Groovy is that there seem to be too many ways to do the same thing, and to understand someone else's code you need to know all the different ways.

BTW, what did you mean by "I agree"? ... or was that someone else's unmarked statement?


 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This reply may be late but I'd like to suggest you look at Miglayout. It's very powerful and easy to use once you learned about the language.
I used to searched and tried lots of things for SwingBuilder because this is not a hot topic and there were not many detailed information available. I wrote my findings and experience about SwingBuilder and Miglayout in 3 articles. Here are the links in case you want to have a look.
https://sites.google.com/site/dracodoc/groovy/swingbuildermiglayout
 
Bill Johnston
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

draco doc wrote:This reply may be late but I'd like to suggest you look at Miglayout. It's very powerful and easy to use once you learned about the language.
I used to searched and tried lots of things for SwingBuilder because this is not a hot topic and there were not many detailed information available. I wrote my findings and experience about SwingBuilder and Miglayout in 3 articles. Here are the links in case you want to have a look.
https://sites.google.com/site/dracodoc/groovy/swingbuildermiglayout



Thank you very much! I appreciate your answer. The more I look around - such as on groovy.codehaus.org (which is a nice site and source of information) - the more it seems to me, coming from a very polished and professional environment in Java, that Groovy is kind of, well, not so terribly professional. It seems like one step beneath beta.

BTW, what is this "I agree. Here's the link: http://aspose.com/file-tools" comment below. I know it's an addvert, but what's with this "I agree"?
 
draco doc
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Groovy didn't have enough fame to get support from companies and users. An new language need to have some shinning points to attract people spend time and resource on it. Java had lots of media coverage in its time, although many of the expectations were proven not realized, it did help java to get critical mass and big company support.
There are many dynamic languages competing for people's resource, functional language have the new hype, and Groovy is "too old" to have the shining appearance.

As for the "I agree" part, I didn't see it in the whole page.Was that inserted by some malware or adware? You can try to open this page with another browser to see if it is still there. Or you can try another machine to check this page. I definitely didn't see it anywhere even if I turn of the adblock extension.
 
Bill Johnston
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No that message is not browser or topic specific.

As to Java. Yes perhaps some folks felt or feel that Java did not deliver all that it was supposed to. What language does deliver all that some folks expect. Some folks are not happy no matter what you give them. To me Java is the greatest thing - so far as computer languages go - since sliced bread. I like some aspects in Groovy too, but as I said before, I think that Groovy also takes one, two or more steps backward in the guise of going forward, by practically eliminating strong typing, removing the need for the semi-colon (which makes Java code much clearer - oddly Groovy folks seem to think this makes Groovy code easier to read ... go figure), and generally allowing the 'shoot yourself in the foot' a lot easier. My opinion - not expected to be shared by others. In my opinion, the bad things about Java are mostly caused by the recent attempts to add in a lot of junk to the language to make it more hip (to my mind like painting my hammer candy apple red and giving it 3 moving parts) and hackers attempts to exploit it. In fact a lot of what is bad with any language or operating system is caused by hackers attempt so exploit them.
 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

draco doc wrote:s for the "I agree" part, I didn't see it in the whole page.Was that inserted by some malware or adware? You can try to open this page with another browser to see if it is still there. Or you can try another machine to check this page. I definitely didn't see it anywhere even if I turn of the adblock extension.


It's an ad placed by the JavaRanch site owner who feels these products are worthy of endorsement. It can be confusing to some visitors, but it's harmless and you can just ignore it.
 
Bill Johnston
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is the 'I agree' part ... like I'm coming in the middle of a conversation I didn't start. Odd way to advertise if you ask me.
 
draco doc
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Groovy make my programming task much, much more easier. If you haven't read this great presentation, I suggest you have a look. It is a tutorial slides by Paul King.

http://www.asert.com.au/pubs/groovy/groovy.pdf

You can see there are so many things that can be done easily and cleanly in Groovy. I mean clean, not just shorter code, but easy to read and understand, difficult to make mistakes.

Bill Johnston wrote:No that message is not browser or topic specific.

As to Java. Yes perhaps some folks felt or feel that Java did not deliver all that it was supposed to. What language does deliver all that some folks expect. Some folks are not happy no matter what you give them. To me Java is the greatest thing - so far as computer languages go - since sliced bread. I like some aspects in Groovy too, but as I said before, I think that Groovy also takes one, two or more steps backward in the guise of going forward, by practically eliminating strong typing, removing the need for the semi-colon (which makes Java code much clearer - oddly Groovy folks seem to think this makes Groovy code easier to read ... go figure), and generally allowing the 'shoot yourself in the foot' a lot easier. My opinion - not expected to be shared by others. In my opinion, the bad things about Java are mostly caused by the recent attempts to add in a lot of junk to the language to make it more hip (to my mind like painting my hammer candy apple red and giving it 3 moving parts) and hackers attempts to exploit it. In fact a lot of what is bad with any language or operating system is caused by hackers attempt so exploit them.

 
Bill Johnston
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't mean to pan Groovy. I've been reading, studying and practicing it for a while now. A lot goes in and come back out though since officially we're not coding in it here yet, but probably will be soon. Thanks for the link though. And yes, if you code Groovy well, it can be clean and clear. The problem is that Groovy makes it a lot easier to make a hash of a program than does Java. It will require careful attention to non code induced coding standards to prevent that from happening.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic