DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

MigLayout: Inevitable Choice for Griffon Users?

Geertjan Wielenga user avatar by
Geertjan Wielenga
·
Sep. 18, 08 · News
Like (0)
Save
Tweet
Share
16.88K Views

Join the DZone community and get the full member experience.

Join For Free

It seems to me that in the same way that Griffon will make Groovy an ever more viable option for Swing developers, so it will make MigLayout increasingly inevitable. This will not be news to anyone who is familiar with Groovy or with MigLayout. However, let's put words aside and look purely at code, for any hold outs out there, as well as for newbies to MigLayout.

Firstly, read My First Griffon App, written yesterday by Josh Reed (also to see how Griffon handles Arctic conditions), where he states:

"I spent the majority of my time on the UI. It was a seemingly endless cycle of tweaking the code and testing with griffon run-app to get it to look the way I wanted. This is no knock on Griffon; writing Java UIs, especially by hand, just plain sucks. After far too long trying to get the standard Java layout managers to do what I want, I did myself a favor and downloaded MigLayout."

That was exactly my experience in Porting to Griffon. The one single pain point that Groovy leaves one with is the design of UIs. Perhaps a GUI Builder as NetBeans IDE has for Swing could help, but that shouldn't be necessary, and I don't believe it is in fact necessary. Firstly, I'd like to point to Metawidget, an automatic UI generator, as explained in detail some time ago here on Javalobby by Richard Kennard, its creator, himself. Secondly, there's MigLayout. As pointed out above (look at the code in Josh Reed's blog entry) and below, we have Gregg Bolinger's MigLayout rewrite (line 9 to 24 below) of my horribly convoluted GridBagLayout from Porting to Griffon:

application(title:'Anagrams', minimumSize:[297, 200], location:[50,50],
    pack:true, locationByPlatform:true) {
    menuBar( id: 'menuBar') {
        menu(text: 'File', mnemonic: 'F') {
            menuItem(aboutAction)
            menuItem(exitAction)
        }
    }
    panel(border:emptyBorder(12), layout:new MigLayout('fill')) {
        label(text: 'Scrambled Word:')
        textField(id: 'scrambledWord', text: bind {model.scrambledWord},
            columns: 20, editable: false,
            constraints: "wrap")
        label(text: 'Your Guess:')
        textField(id: 'guessedWord',
            columns: 20,
            constraints: "wrap")
        label(id:'feedbackLabel', text: bind {model.feedback}, constraints: "wrap")
        panel(name:'buttonPanel', layout:new FlowLayout(FlowLayout.RIGHT),
constraints: "growx, span") {
          button(action: guessWordAction)
          button(action: nextWordAction)
        }
        bean( model, guessedWord: bind {guessedWord.text} )
    }
}

Just for contrast, look at the original GridBagLayout which, aside from its complexity, is about twice as long:

application(title:'Anagrams', minimumSize:[297, 200], location:[50,50],
pack:true, locationByPlatform:true) {
menuBar( id: 'menuBar') {
menu(text: 'File', mnemonic: 'F') {
menuItem(aboutAction)
menuItem(exitAction)
}
}
panel(border:emptyBorder(12)) {
gridBagLayout()
label(text: 'Scrambled Word:',
constraints: gridBagConstraints(
gridwidth: 1, gridheight: 1,
fill: HORIZONTAL, anchor: WEST,
weightx: 0.0, weighty: 0.0,
insets: [0,0,12,6]))
textField(id: 'scrambledWord', text: bind {model.scrambledWord},
columns: 20, editable: false,
constraints: gridBagConstraints(
gridwidth: REMAINDER, gridheight: 1,
fill: HORIZONTAL, anchor: CENTER,
weightx: 1.0, weighty: 0.0,
insets: [0,0,12,0]))
label(text: 'Your Guess:',
constraints: gridBagConstraints(
gridwidth: 1, gridheight: 1,
fill: HORIZONTAL, anchor: WEST,
weightx: 0.0, weighty: 0.0,
insets: [0,0,20,6]))
textField(id: 'guessedWord',
columns: 20,
constraints: gridBagConstraints(
gridwidth: REMAINDER, gridheight: 1,
fill: HORIZONTAL, anchor: CENTER,
weightx: 1.0, weighty: 0.0,
insets: [0,0,20,0]))
label(id:'feedbackLabel', text: bind {model.feedback},
constraints: gridBagConstraints(
gridx: 1, gridy: RELATIVE,
gridwidth: REMAINDER, gridheight: 1,
fill: HORIZONTAL, anchor: CENTER,
weightx: 1.0, weighty: 0.0,
insets: [0,0,20,0]))
button(action: guessWordAction, constraints: gridBagConstraints(
gridx: 1, gridy: RELATIVE,
gridwidth: 1, gridheight: REMAINDER,
fill: NONE, anchor: SOUTHEAST,
weightx: 1.0, weighty: 1.0,
insets: [0,0,0,6]))
button(action: nextWordAction, constraints: gridBagConstraints(
gridwidth: REMAINDER, gridheight: REMAINDER,
fill: NONE, anchor: SOUTHEAST,
weightx: 0.0, weighty: 1.0,
insets: [0,0,0,0]))
bean( model, guessedWord: bind {guessedWord.text} )
}
}

Not only was the above next to impossible to write, but just imagine needing to maintain all of that. And the result is the same as Gregg's rewrite to MigLayout. I believe that the Grails-like structure Griffon offers to Groovy users will make it increasingly attractive, which in turn will make MigLayout an inevitable first choice when it comes to designing the view of Griffon applications. And therefore, in short, if you're a convert to MiGLayout too, please show your appreciation, and your need, by voting to add MiGLayout to the JDK!

Griffon (framework)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Master Spring Boot 3 With GraalVM Native Image
  • DeveloperWeek 2023: The Enterprise Community Sharing Security Best Practices
  • Unlock the Power of Terragrunt’s Hierarchy
  • Important Data Structures and Algorithms for Data Engineers

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: