7 Replies - 2491 Views - Last Post: 30 December 2012 - 04:44 AM Rate Topic: -----

#1 toad87  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 188
  • Joined: 21-May 12

How to implement MiGLayout

Posted 17 December 2012 - 04:37 PM

I have been having a hell of a time figuring out how to implement MiGLayout into my Eclipse Java project.

With the raving reviews and popularity of this layout manager I cannot believe the lack of resources on how to implement the manager.

Can someone give me a step to step tutorial on how to implement the files downloaded from the site? There are six different Jar files and I have no idea where to put them.

After I put the files in the proper places, do I have to import something into my GUI classes?

Any help would be great. Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: How to implement MiGLayout

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: How to implement MiGLayout

Posted 17 December 2012 - 05:13 PM

Once you understand the MiG Layout Cheat Sheet - and that takes some time and practice - it'll click. I don't have a tutorial handy or an example that I could show you that could be explained in less than several pages, but I'll try and give you some pointers about the Cheat Sheet.

The Cheat Sheet defines the shorthand language, the syntax, of MiGLayout statements, and it seems to me that MiGLayout statements are used to define constraints that control how layouts, columns/rows, and components are displayed.

For example, constraints can be defined in the constructor - especially the layout constraints - and then column/row and component layouts can be adjusted on the fly as components are added to containers.

Here's a short example. I created a calculator keypad that has 4 columns and 5 rows on a JPanel. First, I defined the instance variable kepadLayout to be my MigLayout for the JPanel:
    private MigLayout keypadLayout = 
            new MigLayout( "",                        // Layout constraints
                    // Column constraints
                    "[fill][fill][fill][]",
                    // Row constraints
                    "[fill][fill][fill][fill][fill]"  );

The first empty quote is where layout constraints would be specified to affect the whole container, and I didn't have any. I often use the "debug" constraint to show how the components are laid out inside the container.

Then the four sets of square brackets, [fill][fill][fill][], indicate four columns, and the first 3 are to be "filled" by their components.

Similarly for the next 5 sets of square brackets, except those are applied to the 5 rows.

Then my JPanel is initialized as:

JPanel numberPanel = new JPanel( keypadLayout );

So that the keypadLayout becomes the layout for numberPanel. Then as components are added to the panel, additional layout constraints can be specified.

It takes practice to understand what the MiGLayout terms mean and how the constraints affect the layouts. It's not hard, it's just something new to learn.

I know I haven't given you much to work with, but hopefully you're encouraged to keep working at it now that you know others have been there before you and that it's really not that hard.
Was This Post Helpful? 2
  • +
  • -

#3 toad87  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 188
  • Joined: 21-May 12

Re: How to implement MiGLayout

Posted 17 December 2012 - 05:17 PM

Oh no greg. I've studied and read the quick start and cheat sheet. I just don't know how to download and put MiGLayout into my project!

How to add it to classpath and such..
Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: How to implement MiGLayout

Posted 17 December 2012 - 05:27 PM

Oh well, it was a good speech. Maybe it'll come in handy later.

As for adding MiGLayout to your Eclipse project:

Right click your project in the package explorer,

Select Properties

Select Java Build Path from the left column

Select the Libraries tab

Select Add External JARs . . .

Navigate to the MigLayout.jar file you want to add to the project (use the one that says its for Swing)

Select the *.jar file

Select OK.

Now you can use the MiGLayout classes in your project.
Was This Post Helpful? 2
  • +
  • -

#5 toad87  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 188
  • Joined: 21-May 12

Re: How to implement MiGLayout

Posted 17 December 2012 - 05:39 PM

Greg...that was extremely simple and helpful...

I spent 3 days looking online to see how to do this...

Thanks for everything.

This post has been edited by toad87: 17 December 2012 - 05:40 PM

Was This Post Helpful? 0
  • +
  • -

#6 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 822
  • View blog
  • Posts: 2,529
  • Joined: 29-July 11

Re: How to implement MiGLayout

Posted 17 December 2012 - 06:52 PM

View PostGregBrannon, on 18 December 2012 - 12:27 AM, said:

Oh well, it was a good speech. Maybe it'll come in handy later.


:lol:/>
Was This Post Helpful? 0
  • +
  • -

#7 toad87  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 188
  • Joined: 21-May 12

Re: How to implement MiGLayout

Posted 30 December 2012 - 02:09 AM

Hey Greg, just wondering, why do you have 4 columns with a blank fourth column?
Was This Post Helpful? 0
  • +
  • -

#8 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: How to implement MiGLayout

Posted 30 December 2012 - 04:44 AM

I assume you're interpreting the lack of the 'fill' constraint in the fourth column as an indication that the 4th column is empty, and that's not true. All 20 possible locations in the 5 row by 4 column grid have something in them.

I specified the fill constraint in the constructor for the first 3 columns, probably because I knew I'd need it to obtain the desired look at that point. I may have come to the same realization later for the 4th column, adding the fill or even some other constraint when I placed the components there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1