swing - Exception in thread "main" java.lang.IllegalArgumentException: illegal component position -
i working on gui code of java media player here. when try run main class, keep getting following error message :
exception in thread "main" java.lang.illegalargumentexception: illegalcomponent position @ java.awt.container.addimpl(container.java:1085) @ java.awt.container.add(container.java:465) @ dj2.gui.artistspane.<init>(artistspane.java:19) @ dj2.gui.mainframe.<init>(mainframe.java:36) @ dj2.test.guitest.main(guitest.java:21)
i think problem comes artistspane class, since 2 other errors reference it.
here code using artistspane :
public class artistspane extends jpanel{ public artistspane(){ this.setlayout(new flowlayout()); add(new tracksaddremovetoolbar(),flowlayout.trailing);}}
the problem detected @ level of add method. what's wrong it? thanks!
you use flowlayout.trailing not when adding components when defining layout itself, , belongs flowlayout constructor parameter. rid of bit of code add method.
e.g., change
public class artistspane extends jpanel{ public artistspane(){ this.setlayout(new flowlayout()); add(new tracksaddremovetoolbar(),flowlayout.trailing);}}
to
public class artistspane extends jpanel{ public artistspane(){ setlayout(new flowlayout(flowlayout.trailing)); add(new tracksaddremovetoolbar()); } // please place brakcets care }
Comments
Post a Comment