开发者

How do I add a bunch of JPanels to my JFrame using Java Swing?

开发者 https://www.devze.com 2023-03-06 10:04 出处:网络
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

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?

Example Code:

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
}

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

Thanks


How do I add an indefinite number of JPanels to this JFrame?

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

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

(shrugs)

  • 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.
  • ..


JFrame -> JScrollPane -> fathers JPanel then you'll decide which of LayoutManager will lay your bunch of JPanels, by defalut FlowLayout, don't forget to play with PreferedSize for childsPanels

0

精彩评论

暂无评论...
验证码 换一张
取 消