Note that there are some explanatory texts on larger screens.

plurals
  1. POJava view update
    primarykey
    data
    text
    <p>I am working on a complicated piece of work for my level 3 project at University, about 90% of it is going really well, but I keep getting a similar issue throughout the project. </p> <p>The issue I am getting is that when I update a view programatically, the update is not always visible immediately. I have tried a number of different things to try to solve this, calling redraw, repaint, repaintImediately, doLayout, validate, revalidate, etc in different combinations and orders to try to get it to work, and sometimes it does, sometimes it does not. I found that validate works most of the time. </p> <p>The issue I am currently stuck on (and have been for a couple of days now) is regarding a view I have that needs to list data in the style of a property editor (think netbeans/jdeveloper property inspector). The labels for the the properties can all be different widths (but the same height) and the editable fields themselves will normally be the same width, but different heights (text editor vs drop down vs colour picker, etc). For this reason I chose to use the GroupLayout, it took some learning to get it right, but it now is. That is to say, when I initially run the project, it displays correctly, however when I select another component to view (which should update the property viewer), initially nothing happens. When I resize the view, all the old fields disappear, and no new ones come back.</p> <p>Initially I just had this view placed on the screen, but then changed to use a JScrollPane to allow for larger lists of properties. I think that this is the point where things started going wrong, however I can't see how.</p> <p>My question is two fold, what are the surefire ways of forcing a view to update when programatically changed (efficient is good, but at this point reliable is more important). Here I would happily take a link to somewhere in the java documentation that explains it clearly.</p> <p>The second part is related to the following section of code (the setSubject method of my property viewer). Can someone tell me why it isnt working, because I can't think of anything else to do.</p> <pre><code>Iterator&lt;PropertyField&gt; i = propertyFields.iterator(); while(i.hasNext()){ PropertyField p = i.next(); layout.removeLayoutComponent(p.getComponent()); layout.removeLayoutComponent(p.getLabel()); panel.remove(p.getComponent()); panel.remove(p.getLabel()); } propertyFields.clear(); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); panel.setLayout(layout); layout = new GroupLayout(panel); if(this.subject != null){ this.subject.removeObserver(this); } ParallelGroup labelsVertical = layout.createParallelGroup(GroupLayout.Alignment.LEADING); ParallelGroup editsVertical = layout.createParallelGroup(GroupLayout.Alignment.LEADING); SequentialGroup rows = layout.createSequentialGroup(); this.subject = subject; if(subject != null){ this.subject.addObserver(this); ArrayList&lt;Property&gt; props = subject.getProperties(); Iterator&lt;Property&gt;properties = props.iterator(); this.removeAll(); while(properties.hasNext()){ Property p = properties.next(); PropertyField pf = PropertyFieldFactory.getPropertyField(p, this); pf.setValue(subject.getValue(p.getName())); propertyFields.add(pf); labelsVertical.addComponent(pf.getLabel()); editsVertical.addComponent(pf.getComponent()); rows.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(pf.getLabel()).addComponent(pf.getComponent())); } layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(labelsVertical).addGroup(editsVertical)); layout.setVerticalGroup(rows); }; layout.invalidateLayout(panel); layout.layoutContainer(panel); panel.setBounds(0,0, panel.getSize().width, panel.getSize().height); panel.setPreferredSize(panel.getSize()); scroller.getViewport().setViewSize(panel.getSize()); panel.validate(); </code></pre> <p>I have changed the code a little bit, trying to minimise the places where this error could occur. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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