java - JPanel is not updating one of the two pieces of data I need to be updated -


i trying track of supplies stored in knapsack object , create interface shows supplies update using observer/observable implementation. reason when run code, 2 items in knapsack, second item updates , shows expiration date decreasing time change triggered. first 1 not change @ all, if it's static label. please let me know did wrong? in advance! also, i'm super new java programming please information/explanation appreciated.

here code:

package view;  import java.util.observable;  import java.util.observer;  import javax.swing.jlabel;  import javax.swing.jpanel;  import javax.swing.swingutilities;    import supplies.supplies;  import model.adventure;  import model.knapsack;    public class inventoryview extends jpanel implements observer{  	private knapsack knapsack;  	private adventure adventure;  	private jlabel b;    	public inventoryview(adventure adventure) {  		this.adventure=adventure;  		this.knapsack=adventure.getsquad().getknapsack();  		for (supplies supply : knapsack.getsupplies()) {  			b=new jlabel(supply.tostring());  			add(b);  		}  		knapsack.addobserver(this);  	}  	@override  	public void update(observable arg0, object arg1) {  		swingutilities.invokelater(new runnable() {  			public void run() {  				for (supplies supply : knapsack.getsupplies()) {  					b.settext(supply.tostring());  					add(b);  				}				  			}  		});  	}  }

swing lazy when comes container updates (add/removes), allows execute number of add/removes in quick succession without fear system grind halt while attempts update entire container hierarchy on each call.

call revalidate , repaint after have added components. also, make sure jpanel using layout manager capable of supporting multiple children.

you might consider using jlist or jtable instead


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -