Note that there are some explanatory texts on larger screens.

plurals
  1. POJava swing --JPanel on JPanel not showing up
    text
    copied!<p>I trying to add a JPanel to another JPanel but am faced with the problem that the second Jpanel will not show up on the first one.<br> My basic structure of things is as follows --<br> I have a <code>JPanel panel1</code> which has a <code>BoxLayout</code> and by virtue of <code>HorizontalBoxes</code> and <code>VerticalBoxes</code> i keep adding <code>JComponents</code> to it. All <code>JComponents</code> appear on panel1 except for the second <code>JPanel</code>. The code for the second <code>JPanel</code> which wont appear is as follows --</p> <pre><code>public class LabelMacroEditor extends JPanel implements PropertyChangeListener { private static final long serialVersionUID = 1L; private LabelMacroModel model; public LabelMacroEditor(LabelMacroModel bean) { this.model = bean; model.addPropertyChangeListener(this); setupComponents(); validate(); setVisible(true); } public void setupComponents() { Box allButtons = Box.createVerticalBox(); for(MacroModel macroModel : model.getMacroModelList()) { LabelMacroEditorEditableEntity macroEditorEntity = new LabelMacroEditorEditableEntity(macroModel); Box entityBox = Box.createHorizontalBox(); entityBox.add(macroEditorEntity.getUpButton()); entityBox.add(Box.createHorizontalStrut(15)); entityBox.add(macroEditorEntity.getMacroDetailsButton()); entityBox.add(Box.createHorizontalStrut(15)); entityBox.add(macroEditorEntity.getDownButton()); allButtons.add(entityBox); } add(allButtons); } @Override public void propertyChange(PropertyChangeEvent arg0) { revalidate(); } } </code></pre> <p>I have tested <code>LabelMacroEditor</code> in a standalone way by adding it to a JFrame and found that it appears fine. Im assuming its has something to do with come confliction revalidate/setVisible or the like. <br>Am i missing something obvious ?</p> <p>I can post more code from the <code>JPanel</code> that is adding <code>LabelMacroEditor</code> if there is a need.</p> <p>EDIT : The code snippet from where im adding <code>LabelMacroEditor</code> is as follows --</p> <pre><code>private final LabelMacroModel labelMacroModel; private LabelMacroEditor labelMacroEditor; //code to populate labelMacroModel Box verticalBox = Box.createVerticalBox(); // Add all other JComponents to verticalBox labelMacroEditor = new LabelMacroEditor(labelMacroModel); verticalBox.add(labelMacroEditor); add(verticalBox); </code></pre>
 

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