java - how to put two jpanels side by side -


i try put 2 jpanels side side, in moment can not want have code,

this.videopanel= new jpanel(); this.videopanel.setbackground(new color(102, 102, 102)); this.videopanel.setpreferredsize(new dimension(320, 240)); this.videopanel.setlayout(new boxlayout(this.videopanel, 1));  grouplayout layout = new grouplayout(getcontentpane()); getcontentpane().setlayout(layout);  layout.sethorizontalgroup(         layout.createsequentialgroup()         .addgroup(layout.createparallelgroup(grouplayout.alignment.leading)         .addcomponent(this.videopanel, 10, 400, 500)));  layout.setverticalgroup(         layout.createsequentialgroup()         .addgroup(layout.createparallelgroup(grouplayout.alignment.baseline)         .addcomponent(this.videopanel, 10, 400, 500)));  pack(); 

` try put 1 more jpanel:

 this.videopanel1.setbackground(new color(102, 102, 102));  this.videopanel1.setpreferredsize(new dimension(320, 240));  this.videopanel1.setlayout(new boxlayout(this.videopanel1, 2));   grouplayout layout = new grouplayout(getcontentpane());  getcontentpane().setlayout(layout);     layout.sethorizontalgroup(          layout.createsequentialgroup()          .addgroup(layout.createparallelgroup(grouplayout.alignment.leading)          .addcomponent(this.videopanel1, 10, 400, 500)          .addcomponent(this.videopanel, 10, 400, 500)));   layout.setverticalgroup(          layout.createsequentialgroup()          .addgroup(layout.createparallelgroup(grouplayout.alignment.baseline)          .addcomponent(this.videopanel1, 10, 400, 500)          .addcomponent(this.videopanel, 10, 400, 500)));       pack(); 

this code don't work , not give error.

if understand question correctly, want place 2 jpanel side side. @ layout gridlayout.

you'd want setlayout(new gridlayout(1,2)); says 1 row, 2 col


package sscce;  import java.awt.borderlayout; import java.awt.color; import java.awt.gridlayout; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel;  public class sidebyside extends jframe{      public static void main(string[] args) {         new sidebyside();     }      public sidebyside(){         this.setdefaultcloseoperation(jframe.exit_on_close);         this.setsize(100, 75);         this.setlayout(new borderlayout());         this.setvisible(true);          jpanel container = new jpanel();         jpanel panelone = new jpanel();         jpanel paneltwo = new jpanel();          panelone.add(new jlabel("1"));         paneltwo.add(new jlabel("2"));          container.setlayout(new gridlayout(1,2));         container.add(panelone);         container.add(paneltwo);          this.add(container);     }   } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -