Which Layout Manager do you use?

2019-03-18 02:12发布

What java GUI layout manager does everyone use? Lately, I have been using MigLayout, which has some powerful component controls. Just wanted to see what other developers are using other than the standard JDK ones.

22条回答
别忘想泡老子
2楼-- · 2019-03-18 02:51

I'm a bit of Java newbie.

I tried GridBagLayout, gave up, then tried BoxLayout, then gave up, then made my own Custom Layout which worked. With GridBag and Box I put my best guess in and the Layout engines decided to do something different, without any apparent way to debug them.

With my custom layout, I could print out coordinates and widths and heights, to find out where it was going wrong. Its a bit mathy placing things but you've got the full power of java to use rather than the limited vocabulary of one of the builtin layout managers.

Of course it was just for a home project, you'd never be allowed to do this at work.

查看更多
趁早两清
3楼-- · 2019-03-18 02:55

I've always been a big fan of the GridBagLayout. It resembles HTML tables a lot so it is intuitive to those web programmers.

查看更多
劳资没心,怎么记你
4楼-- · 2019-03-18 02:56

The last Swing application I worked on used JGoodies' FormsLayout.

查看更多
疯言疯语
5楼-- · 2019-03-18 02:56

As a general overview, you might find an article I wrote a loooong time ago at sun to be useful. It's not up to date with the latest layout managers, but it concentrates on effective nesting of layout managers, rather than trying to do everything with one layout.

See http://developer.java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr

查看更多
戒情不戒烟
6楼-- · 2019-03-18 02:57

GridBagLayout is usable. Once you get used to using it, it works great. I think the standard JDK layout managers are pretty powerful on their own. Plus, you get to minimize dependency on 3rd party libraries.

查看更多
萌系小妹纸
7楼-- · 2019-03-18 02:57

I use DesignGridLayout for most of my panels.

For the rare panels that DesignGridLayout cannot fully handle, I use a mix of Borderlayout and DesignGridLayout.

With DesigngridLayout you can manually code your layouts with a minimum number of lines of code, that are easy to type and read:

DesignGridLayouut layout = new DesignGridLayout(myPanel);
layout.row().grid(lblFirstName).add(txfFirstName).grid(lblSurName).add(txfSurName);
layout.row().grid(lblAddress).add(txfAddress);
layout.row().center().add(btnOK, btnCancel);

Each row of the panel grid is defined by one line of code. As you can see, "drawing" your panel is quite straightforward.

In addition, I find DesignGridLayout has some unique features (such as its "smart vertical resize").

查看更多
登录 后发表回答