I'm doing my first steps with Java Swing and using Netbeans to draw the layout.
Netbeans creates a static layout, but I need a bit of dynamic.
I already managed to replace the content of JScrollPane
by:
jspIngredients.remove(jpIngredients);
jspIngredients.setViewportView(new JPIngredients(brewRecipe));
pack();
That works fine and my own JPanel
is visible inside the scroll pane after that.
Now I have the same requirement for a panel, but there it doesn't work:
jpPrevStep.removeAll();
jpPrevStep.add(new JPBrewStep(brewRecipe.getBrewStepbyPosition(1)));
jpPrevStep.revalidate();
jpPrevStep.repaint();
jpPrevStep
is a panel which is part of the Netbeans created layout.
Inside this panel I wand to show my own content, which is also a panel (named JPBrewStep
).
But nothing is shown in the window, so the .removeAll()
works, but adding the new content does not.
I also tried to add my new content via a layout instead direct:
jpCurrentStep.remove(jPanel1);
jPanel1 = new JPBrewStep(brewRecipe.getBrewStepbyPosition(1));
javax.swing.GroupLayout jpCurrentStepLayout = new javax.swing.GroupLayout(jpCurrentStep);
jpCurrentStepLayout.setHorizontalGroup(jpCurrentStepLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
jpCurrentStepLayout.setVerticalGroup(jpCurrentStepLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanel1,javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,Short.MAX_VALUE));
jpCurrentStep.revalidate();
jpCurrentStep.repaint();