swing - Java GroupLayout Exception -
public class grouplayout implements runnable { public static void main(string[] args) { swingutilities.invokelater(new grouplayout()); } @override public void run() { jframe jframe = new jframe(); grouplayout layout = new grouplayout(jframe.getcontentpane()); jframe.getcontentpane().setlayout(layout); layout.setautocreategaps(true); layout.setautocreatecontainergaps(true); jlabel jlabel1 = new jlabel("a"); jlabel jlabel2 = new jlabel("b"); jlabel jlabel3 = new jlabel("c"); jlabel jlabel4 = new jlabel("d"); layout.setverticalgroup( layout.createsequentialgroup() .addgroup(layout.createparallelgroup(grouplayout.alignment.baseline) .addcomponent(jlabel1) .addcomponent(jlabel2)) .addgroup(layout.createparallelgroup(grouplayout.alignment.baseline) .addcomponent(jlabel3) .addcomponent(jlabel4))); jframe.pack(); jframe.setvisible(true); } }
i'm trying run i've got following exception:
exception in thread "awt-eventqueue-0" java.lang.illegalstateexception: javax.swing.jlabel[,0,0,0x0,invalid,alignmentx=0.0,alignmenty=0.0,border=,flags=8388608,maximumsize=,minimumsize=,preferredsize=,defaulticon=,disabledicon=,horizontalalignment=leading,horizontaltextposition=trailing,icontextgap=4,labelfor=,text=a,verticalalignment=center,verticaltextposition=center] not attached horizontal group
what's problem? how can fix it?
you have specify both horizontal , vertical layout, see grouplayout giving error java swing
i suggest use tool build gui.
Comments
Post a Comment