alicedimarco
alicedimarco

Reputation: 325

Layout suggestions for GUI?

So I want to make a new JList and a new JPanel at the bottom, but I'm not too familiar with the BoxLayout, FlowLayout and the like. What do you suggest so I can make my GUI turn into something like this:

I drew this on Paint, excuse my drawing.

Excuse my drawing and thanks to anyone who can help! :)

Edit: What does this do? JPanel.setLayout(new BoxLayout(JPanel, BoxLayout.PAGE_AXIS));

Upvotes: 4

Views: 259

Answers (2)

cdeszaq
cdeszaq

Reputation: 31280

Use MigLayout. It is very easy to use and has only a very small learning curve. It can easily handle the layout you are going for. Specifically, start with the Quick Start Guide, and then the Whitepaper for the rest of the API)

The specific pieces to look at with MigLayout are docked elements (to the right and bottom, it looks like) and fill, since it also looks like you want things to take the whole space.

Other than that, you probably won't need much more for specifying the layout.

As an example, using MigLayout and SwingBuilder in the Griffon framework, here's how I would lay out what you have:

migLayout(layoutConstraints: 'fill, wrap 2', 
    columnConstraints: '[grow|]', 
    rowConstraints: '[grow|]')

panel (constraints: 'spany 2, grow') { 
    // Main content with the picture go in here 
}
list(constraints: 'grow') { 
    // Top list 
}
list(constraints: 'grow') { 
    // Bottom list 
}

panel(constraints: 'grow') { 
    // Bottom panel 
}
panel() { 
    // Button panel 
}

There are likely many better ways to do this, and I haven't put the layout together and run it myself so I'm not 100% sure it works, but it should serve as a good starting point.

Upvotes: 3

Slash
Slash

Reputation: 506

DEither use a GridBadLayout, or use nested panels with BorderLayout. You need to have some levels of JPanel containers that define the layout, and then add the functional components on them.

For your example, I would start with a panel in the Center (Panel A) and a panel on the East border (Panel B). then use a BoxLayout for panel B and add the JList, JButton, JLabel, and Jlists, as well as the remove tag buttons.

For the panel A, add yet another container panel on the south border (Panel C), another on the center (Panel D) and another on the east border (Panel E). Add the new two lists at the Panel E with a boxlayout, and the pic on Panel C.

Hope it helps

Upvotes: -1

Related Questions