java - GroupLayout - How to make layout maintain the same arrangement after resize -
i have set constraints components resized window. problem order destroyed because positions off. there equivalent gridbagconstraints.anchor in grouplayout?
before resize :
after resize :
[edit] here code : [edit # 2] here code runnable :
import java.awt.font; import javax.swing.grouplayout; import javax.swing.grouplayout.alignment; import javax.swing.jbutton; import javax.swing.jlabel; import javax.swing.jpanel; import javax.swing.jscrollpane; import javax.swing.jtable; import javax.swing.jtextfield; import javax.swing.layoutstyle.componentplacement; import javax.swing.listselectionmodel; import javax.swing.table.defaulttablemodel; import javax.swing.table.tablemodel; @suppresswarnings("serial") public class connectui extends jpanel { private static jtextfield textfield; private static jtable table; public static jbutton submit; /** * create panel. */ public static void main(string[] args){ jframe f = new jframe(); f.setsize(500, 500); f.setdefaultcloseoperation(jframe.exit_on_close); f.setcontentpane(new connectui()); f.setvisible(true); } public connectui() { textfield = new jtextfield(); textfield.setcolumns(10); jlabel lblavailable = new jlabel("available : "); lblavailable.setfont(new font("tahoma", font.plain, 12)); jlabel lblusername = new jlabel("username : "); lblusername.setfont(new font("tahoma", font.plain, 12)); jscrollpane scrollpane = new jscrollpane(); submit = new jbutton("submit"); jlabel lblclient = new jlabel("client"); lblclient.setfont(new font("tahoma", font.plain, 12)); jlabel lblwarning = new jlabel("username must not exceed 15 characters , server must selected"); lblwarning.setfont(new font("tahoma", font.plain, 12)); grouplayout grouplayout = new grouplayout(this); grouplayout.sethorizontalgroup( grouplayout.createparallelgroup(alignment.leading) .addgroup(grouplayout.createsequentialgroup() .addgroup(grouplayout.createparallelgroup(alignment.leading) .addgroup(grouplayout.createsequentialgroup() .addcontainergap() .addgroup(grouplayout.createparallelgroup(alignment.leading) .addcomponent(scrollpane, grouplayout.preferred_size, grouplayout.default_size, grouplayout.preferred_size) .addgroup(grouplayout.createsequentialgroup() .addgroup(grouplayout.createparallelgroup(alignment.leading) .addcomponent(lblusername, grouplayout.default_size, 0, short.max_value) .addcomponent(lblavailable, grouplayout.default_size, grouplayout.default_size, short.max_value)) .addgap(452)))) .addgroup(grouplayout.createsequentialgroup() .addgap(196) .addcomponent(lblclient, grouplayout.default_size, 132, short.max_value) .addgap(134))) .addgap(38)) .addgroup(grouplayout.createsequentialgroup() .addgap(200) .addcomponent(submit, grouplayout.default_size, 102, short.max_value) .addgap(198)) .addgroup(grouplayout.createsequentialgroup() .addgap(68) .addcomponent(lblwarning, grouplayout.default_size, 357, short.max_value) .addgap(75)) .addgroup(grouplayout.createsequentialgroup() .addgap(120) .addcomponent(textfield, grouplayout.default_size, 150, short.max_value) .addgap(230)) ); grouplayout.setverticalgroup( grouplayout.createparallelgroup(alignment.leading) .addgroup(grouplayout.createsequentialgroup() .addcontainergap() .addcomponent(lblclient, grouplayout.default_size, 38, short.max_value) .addgroup(grouplayout.createparallelgroup(alignment.trailing) .addgroup(grouplayout.createsequentialgroup() .addgap(31) .addcomponent(lblusername, grouplayout.default_size, grouplayout.default_size, short.max_value)) .addgroup(grouplayout.createsequentialgroup() .addpreferredgap(componentplacement.related, 11, short.max_value) .addcomponent(textfield, grouplayout.preferred_size, grouplayout.default_size, grouplayout.preferred_size))) .addpreferredgap(componentplacement.related) .addcomponent(lblavailable, grouplayout.default_size, 4, short.max_value) .addgap(18) .addcomponent(scrollpane, grouplayout.default_size, 210, short.max_value) .addgap(37) .addcomponent(lblwarning, grouplayout.default_size, 39, short.max_value) .addpreferredgap(componentplacement.related) .addcomponent(submit, grouplayout.default_size, 31, short.max_value) .addgap(69)) ); table = new jtable(); table.setmodel(new defaulttablemodel( new object[][] { {null, null, null}, {null, null, null}, {null, null, null}, }, new string[] { "room", "host", "ip" } ) { boolean[] columneditables = new boolean[] { false, false, false }; public boolean iscelleditable(int row, int column) { return columneditables[column]; } }); table.setselectionmode(listselectionmodel.single_selection); scrollpane.setviewportview(table); setlayout(grouplayout); } }
Comments
Post a Comment