且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Java swing中切换屏幕

更新时间:2023-12-04 15:38:19

使用Swing的一般方法是使用适当的策略(通常为CardLayout,但细节决定成败). 此GUI 显示了其他一些选项(JSplitPane和嵌套布局):

The general approach using Swing would be to either combine all the GUI elements 'screens' in one top level container using the appropriate strategy (generally a CardLayout, but the devil is in the details). This GUI shows some other options (JSplitPane & nested layouts):

另请参阅此答案.

对于逻辑上在 容器中的其他任何功能,请使用(可能)模式对话框或JOptionPane.例如.从主机架弹出的登录:

For any other functionality which would logically be in a different container, use a (possibly) modal dialog or a JOptionPane. E.G. a log-in, popped from the main frame:

要考虑的另一件事是,Swing(带有台式机显示器)使我们能够向用户提供更丰富的组件集.例如,通常通过在每个目录中使用一个列表来浏览Android SD卡文件系统,然后更改列表的内容或在输入新目录时进行查看.在Swing中,您可以为此使用一个JTree.因此,相比用于选项卡或电话的桌面GUI工具包,对不同屏幕"的需求要少得多.

Another thing to take into account is that Swing (with a desktop monitor) allows us to offer a richer set of components to the user. For instance, surfing around the Android SD card file system would generally be achieved by using one list per directory, and either changing the content of the list or view on entering a new directory. In Swing you might use a single JTree for that. So there is much less need for 'different screens' in a desktop GUI toolkit, over one designed to be used on a tab or phone.

这是文件浏览器中使用的树.