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 callingsetVisible(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
精彩评论