Note that there are some explanatory texts on larger screens.

plurals
  1. POJPanel with different Layout that its JFrame
    text
    copied!<p>I want to know can we have a JPanel with a Layout other than its Parent JFrame. For example. If I have JFrame with Border Layout and we have a JPanel embedded on it and it is having different Layout. Is it possible ?</p> <p>I am trying to do it. But this way the components of that JPanel are not showing.</p> <p>Here comes the problem in detail : </p> <p>I have a JFrame and layout for it is Border Layout. I am adding a JPanel on this frame. If I donot set any Layout for the JPanel. All components of JPanel are displaying on the window but When I am setting Grid Layout for JPanel, Components of JPanel are not visible. I am adding Layout to JPanel so as to align the Components. Below is my code :</p> <p>I have a main class, a frame class and Jpanel class.</p> <pre><code> public class AppMain { public static void main(String[] args) { AppPage1 page1 = new AppPage1("test"); page1.setVisible(true); } } public class AppPage1 extends JFrame { public AppPage1(String title) throws HeadlessException { super(title); this.setLayout(new BorderLayout()); addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) { setExtendedState(MAXIMIZED_BOTH); } }); //Panel for logo JLabel testLogo = new JLabel(""); testLogo.setIcon(new javax.swing.ImageIcon("test.JPG")); List&lt;JComponent&gt; componentList = new ArrayList&lt;JComponent&gt;(); componentList.add(testLogo); PagePanel logoPanel = new PagePanel(componentList,null); this.add(logoPanel, BorderLayout.NORTH); //Panel for Button and checkboxes JLabel panelTitle = new JLabel("test Wizard"); JRadioButton rdButton_ExistingConfigurationFile = new JRadioButton("Existing Configuration File"); JRadioButton rdButton_ConfigureNewPropertyFile = new JRadioButton("Configure new Property File"); componentList = new ArrayList&lt;JComponent&gt;(); componentList.add(panelTitle); componentList.add(rdButton_ExistingConfigurationFile); componentList.add(rdButton_ConfigureNewPropertyFile); PagePanel buttonPanel = new PagePanel(componentList,new GroupLayout(this)); this.add(buttonPanel, BorderLayout.CENTER); this.pack(); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); validate(); } } public class PagePanel extends JPanel { public PagePanel(List&lt;JComponent&gt; componentList, LayoutManager layOutManager) { this.setBackground(Color.decode("#4E6987")); if (layOutManager != null) { this.setLayout(null); } for (JComponent jComponent : componentList) { jComponent.setBackground(Color.decode("#4E6987")); this.add(jComponent); } } } </code></pre> <p>Thanks in Advance Ravi Kumar</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload