Question

I've been thrown into a desktop application project that is behind schedule in the hopes that I can get the project moving again, but alas, I have very little experience with desktop application development.

My predacessor seemed to know what he was doing, sort of, but never managed to get anything finished, so I am left trying to patch up the messs and get the project out the door.

The application uses Griffon as a framework, and MigLayout as the layout manager, and I think I have the hang of most of it, but I cannot figure out how to get the grow behavior the specs require.

Here's the view that I'm working with :

application(title: 'MyApp',
        preferredSize: [320, 240],
        pack: true,
        locationByPlatform: true,
        iconImage: imageIcon('/griffon-icon-48x48.png').image,
        iconImages: [imageIcon('/griffon-icon-48x48.png').image,
                imageIcon('/griffon-icon-32x32.png').image,
                imageIcon('/griffon-icon-16x16.png').image]) {
    panel(layout: new MigLayout()) {
        label 'Root Directory:', constraints: 'split, span'
        textField text: 'Put RootDir here', constraints: 'growx'
        button 'Dialog', constraints: 'wrap'

        label 'To be Processed:'
        button 'Go button', constraints: 'spany 3'
        label 'Processed:', constraints: 'wrap'

        scrollPane(constraints: 'center, grow') {
            list listData: (1..20).collect { "Very Long Line $it" }
        }
        scrollPane(constraints: 'center, grow, wrap') {
            list listData: (1..5).collect { "Line $it" }
        }

        label 'info about files'
        label 'info about files', constraints: 'wrap'

        progressBar constraints: 'span, growx, wrap'
        progressBar constraints: 'span, growx'
    }
}

When I drag the window larger, the text field at the top and the two progress bars at the bottom are supposed to stretch to fill the space horizontally, and the two lists are supposed to stretch in both directions. The rest of the elements' sizes should remain the same.

No matter what I try, I can only get the top text box to stretch if I set it's columns property very large, and even then it only will go out to show that many columns, not any bigger.

The lists also will not grow vertically at all, and the best i've been able to get is to have the right list grow to some unknow size, and then the left list will grow.

The progress bars will grow to as large as the containing panel does, which is fine if I can get the containing panel to fill the full window.

So, what key piece am I missing? I am sure it is some small element, but no matter how hard I try, I can't seem to get things to grow correctly. Any help is greatly appreciated.

Was it helpful?

Solution

I think the issue is that your root panel is not resizing, so none of the elements internal to that panel ever need to resize.

Try changing:

panel(layout: new MigLayout()) {

to

panel(layout: new MigLayout('fill')) {

OTHER TIPS

As others have commented, you must set appropriate layout constraints when instantiating MigLayout. If you have the miglayout plugin then the code can be shortened to the following

application(title: ...) {
    migLayout layoutConstraints: 'fill'
    label 'Root Directory:', constraints: 'split, span'
    ...
}

Try

panel(layout: new MigLayout(**"fillx"**)) {
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top