Closed 。这个问题是基于意见的 /help/closed-questions 。目前不接受答案。
我正在开发一个显示图像并播放数据库中的声音的应用程序。我正在尝试决定是否使用单独的 JFrame 从 GUI 将图像添加到数据库中。
我只是想知道使用多个 JFrame 窗口是否是一个好的做法?
我只是想知道使用多个 JFrame 是否是一个好的做法?
坏(坏,坏)做法。
用户不友好:当用户希望只看到一个图标时,却在任务栏中看到了多个图标。再加上编码问题的副作用..
A nightmare to code and maintain:
A 模态对话框 http://docs.oracle.com/javase/tutorial/uiswing/misc/modality.html 提供了将注意力集中在该对话框内容上的简单机会 - 选择/修复/取消此对话框,then 继续。多帧则不然。
当单击父级时,带有父级的对话框(或浮动工具栏)将出现在前面 - 如果这是所需的行为,则必须在框架中实现它。
在一个 GUI 中显示许多元素的方法有很多种,例如:
CardLayout http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html (short demo. https://stackoverflow.com/a/5786005/418556 ). Good for:
显示类似向导的对话框。
显示具有关联组件的项目的列表、树等选择。
在无组件和可见组件之间翻转。
JInternalFrame/JDesktopPane http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html 通常用于MDI http://en.wikipedia.org/wiki/Multiple_document_interface .
JTabbedPane http://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html 对于组件组。
JSplitPane http://docs.oracle.com/javase/tutorial/uiswing/components/splitpane.html 一种显示两个组件的方式,其中一个或另一个组件之间的重要性(大小)根据用户正在执行的操作而变化。
JLayeredPane http://docs.oracle.com/javase/tutorial/uiswing/components/layeredpane.html 许多良好的..分层组件。
JToolBar http://docs.oracle.com/javase/tutorial/uiswing/components/toolbar.html 通常包含多组操作或控件。可以在 GUI 周围拖动,或者根据用户需要完全关闭它。如上所述,将根据父级的操作最小化/恢复。
作为 a 中的项目JList http://docs.oracle.com/javase/tutorial/uiswing/components/list.html (下面是简单的例子)。
作为 a 中的节点JTree http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html .
Nested layouts https://stackoverflow.com/a/5630271/418556 .
但如果这些策略不适用于特定用例,请尝试以下方法。建立单一主JFrame
,则有JDialog http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html or JOptionPane http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#features 使用框架作为对话框的父级,为其余自由浮动元素显示实例。
许多图像
在这种情况下,多个元素是图像,最好使用以下任一选项:
A single JLabel
(centered in a scroll pane) to display whichever image the user is interested in at that moment. As seen in ImageViewer https://stackoverflow.com/a/13463684/418556 .
单排JList
。正如所见这个答案 https://stackoverflow.com/a/9544652/418556 。仅当它们的尺寸相同时,“单行”部分才有效。或者,如果您准备动态缩放图像,并且它们都是相同的宽高比(例如 4:3 或 16:9)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)