简体   繁体   中英

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:

我在油漆上画了这个,请原谅。

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

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM