java - JPanel not refreshing upon selection with JComboBox -



java - JPanel not refreshing upon selection with JComboBox -

i attempting write pretty short class "ties" jpanel jcombobox. think have logic down, nil happens when select new using jcombobox... here (more or less) code:

private displaypanel currentdisplay; //a displaypanel extended jpanel id field, , overriden .equals() method private jcombobox selector; private list<displaypanel> displays; public selectionpanel(displaypanel panel){ displays = new arraylist<displaypanel>(); selector = new jcombobox(new string[]{panel.id}); currentdisplay = panel; selector.addactionlistener(this); this.add(selector); this.add(currentdisplay); this.displays.add(panel); } public void addnewselection(displaypanel panel){ displays.add(panel); selector.additem(panel.id); } @override public void actionperformed(actionevent e) { jcombobox source = (jcombobox) e.getsource(); string id = (string) source.getselecteditem(); for(displaypanel display: displays) if(id.equals(display.id)) currentdisplay = display; this.validate(); }

i assuming need override repaint() function somehow, not sure best way that.

here (more or less) code:

which doesn't help because don't know context of how code used. improve help post sscce when asking question.

currentdisplay = display;

that line of code doesn't seem correct. alter value of variable. not add together panel gui. basic code be:

panel.remove( theoldpanel ); panel.add( thenewpanel ); panel.revalidate(); panel.repaint();

however, cardlayout you, proper solution follow aardvarkk's suggestion.

java swing jpanel jcombobox

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -