本文介绍了如何使用Java Swing将一堆JPanels添加到我的JFrame中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成了一堆JPanels,然后将它们传递给扩展JFrame的类.如何向此JFrame中添加不确定数量的JPanel.我还在阅读有关JScrollPane的信息,是否应该以某种方式将其纳入设计中?

I generate a bunch of JPanels and then pass them into a class that extends JFrame. How do I add an indefinite number of JPanels to this JFrame. I was also reading about JScrollPane should I incorporate this somehow into the design?

示例代码:

class foo extends JPanel
{
  //generate JPanels
}

class bar extends JFrame
{
  //grab some amount of foo classes and put them into this JFrame and show it
}

在显示此JFrame时,我还需要注意什么吗?

Also is there anything I need to watch out for when showing this JFrame?

谢谢

推荐答案

CardLayoutJDesktopPane/JInternalFrameJTabbedPaneJScrollPane-有很多选项.

CardLayout, JDesktopPane/JInternalFrame, JTabbedPane, JScrollPane - there are a number of options.

(耸耸肩)

  • 在EDT上构建并显示GUI组件.
  • pack() GUI,然后设置位置并调用setVisible(true).
  • 不要依赖内容窗格的默认布局.
  • 不要在顶级容器中实现自定义绘画.
  • ..
  • Construct and show GUI components on the EDT.
  • pack() the GUI before setting the position and calling setVisible(true).
  • Don't rely on the default layouts of content panes.
  • Don't implement custom painting in a top level container.
  • ..

这篇关于如何使用Java Swing将一堆JPanels添加到我的JFrame中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 17:08