简体   繁体   English

Java中的Best Swing布局解决方案

[英]Best swing's layout solution in java

i'm trying to reproduce a mail client like osx lion's client. 我正在尝试重现像osx lion的客户端这样的邮件客户端。 So i've to do something like: 所以我必须要做一些类似的事情:

osx lion的客户邮件

I don't know what is the best solution of layout to do that.. can someone give me some suggest? 我不知道什么是布局的最佳解决方案。有人可以给我一些建议吗? thanks!!! 谢谢!!!

The solution would be to use a number of different layouts and components , nested within each other until you have built up the overall layout you are looking for. 解决方案是使用彼此嵌套的许多不同布局和组件 ,直到建立了所需的总体布局。 Typically you would use JPanels for each of the nested areas, and perhaps a JSplitPane for the resizable window areas. 通常,您将对每个嵌套区域使用JPanels,对于可调整大小的窗口区域可能使用JSplitPane。

You'll may find you need to write (or find in a 3rd party library library) a number of custom components for specific features. 您可能会发现需要为特定功能编写(或在第3方库中找到)许多自定义组件

At a guess, you could do most of the mail client layout with a combination of BorderLayout and GridBagLayout . 猜测一下,您可以结合使用BorderLayoutGridBagLayout来完成大多数邮件客户端布局。 But you might also want to consider MigLayout , which is a great general purpose layout manager that is very flexible. 但是您可能还需要考虑MigLayout ,这是一个非常灵活的通用布局管理器。

If you haven't done so alredy, you should do the excellent Java Swing Tutorials 如果您还没有做那么好的事情,那么您应该做出色的Java Swing教程

PS WindowBuilder is a great tool for quickly prototyping, but for more complex GUI designs like this I think you are ultimately better hand coding them. PS WindowBuilder是用于快速制作原型的好工具,但是对于像这样的更复杂的GUI设计,我认为您最终会更好地手工编码它们。

Overall for that screenshot, a horizontal box layout might be what you're after (laying out the components from left to right to fill the space.) 总体而言,该屏幕快照可能是您想要的(将组件从左到右布置以填充空间)。

You may well need to nest other layouts inside that though, as you would with most reasonably sized UIs. 不过,您可能需要将其他布局嵌套在其中,就像使用大小最合理的UI一样。

This is something you'd use JSplitPane for. 这是您要使用JSplitPane的目的。 If you don't want the user to be able to resize the division between left and right you'd use BorderLayout where the left would go work like: 如果您不希望用户调整左和右之间的距离,请使用BorderLayout,其中左将起作用:

panel = new JPanel( new BorderLayout() );
panel.add( new LeftPanel(), BorderLayout.WEST );
panel.add( new CentralPanel(), BorderLayout.CENTER );

That way the LeftPanel would be sized according its preferred width, and the center would be given the remaining width and height so it would resize itself as the user grew and shrank the window, but he left panel would be fixed width and grow and shrink in the height. 这样,LeftPanel的大小将根据其首选宽度进行调整,并为中心指定剩余的宽度和高度,以便随着用户的成长和缩小窗口而调整其自身的大小,但是他的左面板将保持固定的宽度并在其中扩大和缩小高度。

If you're just wondering about general purpose layout TableLayout is by far the simplest vs most flexible. 如果您只是想知道通用布局,那么TableLayout是迄今为止最简单还是最灵活的布局。 Not many layout problems can't be conquered using it, and its easy to understand (as opposed to SpringLayout, GroupedLayout, etc) and far less code and more robust than GridBagLayout. 使用它并不能解决很多布局问题,它易于理解(与SpringLayout,GroupedLayout等相对),并且代码少得多,并且比GridBagLayout更健壮。

http://java.sun.com/products/jfc/tsc/articles/tablelayout/ http://java.sun.com/products/jfc/tsc/articles/tablelayout/

But for the problem you describe I don't think you have to use it. 但是对于您描述的问题,我认为您不必使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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