Note that there are some explanatory texts on larger screens.

plurals
  1. POJava swing -- Jpanel not rerendering/repainting itself
    text
    copied!<p>Im using a JPanel with propertyChangeListener and want it to rerender itself based on whenever a particular variable <code>model</code> changes. My code for the same is as follows --<br></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(); JScrollPane macroModelScroller = new JScrollPane(allButtons); macroModelScroller.setPreferredSize(new Dimension(300, 200)); 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(macroModelScroller); } @Override public void propertyChange(PropertyChangeEvent arg0) { revalidate(); repaint(); } } </code></pre> <p>When i use the debug mode in eclipse i can see that whenever there is a change to <code>model</code> it triggers off the call <code>propertyChange</code> and it also runs over <code>revalidate</code> and <code>repaint</code> but only the <code>JPanel</code> display remains the same. It does not seem to be rerendering itself. Anything fundamental that I'm missing here ?</p> <p>EDIT :</p> <p>An example snippet of a property im changing is as follows --</p> <pre><code>labelMacroModel.addMacroModel(addedMacroModel); </code></pre> <p>where <code>labelMacroModel</code> is of the type <code>LabelMacroModel</code> and <code>addedMacroModel</code> is of the type <code>Macro</code></p> <p>Now the relevant part of <code>LabelMacroModel</code> class that fires off the property change is as follows --</p> <pre><code>private List&lt;MacroModel&gt; macroModelList;// this is the list of all MacroModels public void addMacroModel(MacroModel macroModel) { macroModelList.add(macroModel); pcs.fireIndexedPropertyChange("LabelMacroModel", macroModelList.size(), null, macroModel); } </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