Gap size after placing JSeparator in Java Swing -


i have simple problem here in java swing. simplified code following snippet. not sure how can minimize gap size between horizontal jseparator next jtextfield, current code generates huge gap between two.

        grouplayout layout = new grouplayout(jpanel1);                   jpanel1.setlayout(layout);          layout.sethorizontalgroup(layout.createparallelgroup()             .addgroup(layout.createsequentialgroup()                   .addgroup(layout.createsequentialgroup()                         .addcomponent(button)                       ))                   .addcomponent(jseparator)                   .addcomponent(jtextfield)             );         layout.setverticalgroup(layout.createsequentialgroup()                 .addcomponent(button)                 .addcomponent(jseparator)                 .addcomponent(jtextfield)             );   

and in general, how can control gap size integer represented value, instead of using addpreferredgap?

thank you.

okay, window generated code posted above: enter image description here

you can see space between jseparator , jtextfield wide.

absent sscce, problem appears in code don't show. parent container's layout or pack() may involved. note default layout of jframe borderlayout; default position center. here's sscce compare code.

addendum: commenting parent of grouplayout panel jpanel, asked following,

do know how make work in situation?

yes, give enclosing jpanel suitable layout, e.g. gridlayout shown below. latter behaves borderlayout.center of jframe in regard.

grouppanel

import java.awt.eventqueue; import java.awt.gridlayout; import javax.swing.grouplayout; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.jseparator; import javax.swing.jtextfield;  /** @see http://stackoverflow.com/questions/6769722 */ public class grouppanel extends jpanel {      private final jbutton button = new jbutton("start");     private final jseparator jseparator = new jseparator();     private final jtextfield jtextfield = new jtextfield(10);      public grouppanel() {         grouplayout layout = new grouplayout(this);                   this.setlayout(layout);         layout.setautocreategaps(true);         layout.setautocreatecontainergaps(true);         layout.sethorizontalgroup(layout.createparallelgroup()             .addcomponent(button)             .addcomponent(jseparator)             .addcomponent(jtextfield)         );         layout.setverticalgroup(layout.createsequentialgroup()             .addcomponent(button, grouplayout.preferred_size,                 grouplayout.default_size, grouplayout.preferred_size)             .addcomponent(jseparator, grouplayout.preferred_size,                 grouplayout.default_size, grouplayout.preferred_size)             .addcomponent(jtextfield, grouplayout.preferred_size,                 grouplayout.default_size, grouplayout.preferred_size)         );     }      private static void display() {         jframe f = new jframe("grouppanel");         f.setdefaultcloseoperation(jframe.exit_on_close);         f.setlayout(new gridlayout(1, 0));         f.add(new grouppanel());         f.add(new grouppanel());         f.pack();         f.setlocationrelativeto(null);         f.setvisible(true);     }      public static void main(string[] args) {         eventqueue.invokelater(new runnable() {              @override             public void run() {                 display();             }         });     } } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -