user interface - GridBagLayout strategy in Java -


i'm struggling putting vertical space between 2 components in gridbaglayout ,

(1) putting space between first 2 components ,

(2) understanding better strategy laying out components based on picture below.

below (a) have, (b) want, (c) i've made in tab, , (d) code tab i'm having trouble with.

i have this , can see there isn't space between 2 lines. can't insets work properly

enter image description here

i want this enter image description here

i able make this, think did inefficiently. enter image description here

and here's code chinese remainder thm tab:

import java.awt.*; import javax.swing.*;   public class crttab extends jpanel{  // stackoverflow public static void main(string[] args){     jframe frame = new jframe();     frame.setdefaultcloseoperation(jframe.exit_on_close);     frame.setlocation(200, 50);     frame.setpreferredsize(new dimension(600, 674));     frame.add(new crttab());     frame.pack(); //fit gui components nicely     frame.setvisible(true); }  /** global variables */  //entry labels & corresponding text field // α ≡ (mod m) jlabel alphalabel1; // α ≡ jformattedtextfield ienter; // enter jlabel leftpar1; // (mod jformattedtextfield menter; // enter m jlabel rightpar1; // )  // α ≡ j (mod n) jlabel alphalabel2; // α ≡ jformattedtextfield jenter; // enter j jlabel leftpar2; // (mod jformattedtextfield nenter; // enter n jlabel rightpar2; // )   //solve/import buttons & answer label jbutton solvebutton;  jbutton importbutton; jtextpane crtanswer; // α ≡ _ (mod m*n)   //table (showing gcd computation) maintenance jtable t; jscrollpane scroller;   /**construct crt tab  */ crttab() {     setlayout(new gridbaglayout());     gridbagconstraints c = new gridbagconstraints();      // α ≡ (mod m) in row 1 *****************************************************************      //α ≡ label     alphalabel1 = new jlabel("α ≡", jlabel.center);     alphalabel1.setfont(new font("arial", font.plain, 22));      //constraints     c.fill = gridbagconstraints.both;     c.anchor = gridbagconstraints.baseline;     c.weightx = 0.01;     c.weighty = 1;     c.gridx = 0;     c.gridy = 0;     c.insets = new insets(0, 40 , 0, 0); //top, left, bottom, right     add(alphalabel1, c);      //enter     ienter = new jformattedtextfield();     ienter.setfont(new font("arial", font.plain, 22));     alphalabel1.setlabelfor(ienter);      //constraints     c.weightx = 35.0;     c.insets = new insets(0, 5 , 0, 0); //top left bottom right     c.gridx = 1;     add(ienter, c);      //(mod label     leftpar1 = new jlabel("(mod");     leftpar1.setfont(new font("arial", font.plain, 22));      //constraints     c.weightx = 0.01;     c.gridx = 2;     c.insets = new insets(0, 10, 0, 0); //top, left, bottom, right     add(leftpar1, c);      //enter m     menter = new jformattedtextfield();     menter.setfont(new font("arial", font.plain, 22));     leftpar1.setlabelfor(menter);      //constraints     c.weightx = 35.0;     c.insets = new insets(0, 10 , 0, 0); //top, left, bottom, right     c.gridx = 3;     add(menter, c);      //) label     rightpar1 = new jlabel(")");     rightpar1.setfont(new font("arial", font.plain, 22));      //constraints     c.weightx = 0.01;     c.fill = gridbagconstraints.remainder;     c.gridx = 4;     c.insets = new insets(0, 5, 0, 40); //top, left, bottom, right     add(rightpar1, c);       // row 2 ******************************************************************************************0      //α ≡ label     alphalabel2 = new jlabel("α ≡", jlabel.center);     alphalabel2.setfont(new font("arial", font.plain, 22));      //constraints     c.weighty = 3;     c.gridx = 0;     c.anchor = gridbagconstraints.below_baseline;     c.fill = gridbagconstraints.horizontal;     c.insets = new insets(0, 40 , 0, 0); //top, left, bottom, right     add(alphalabel2, c);      //enter j     jenter = new jformattedtextfield();     jenter.setfont(new font("arial", font.plain, 22));     alphalabel2.setlabelfor(jenter);      //constraints     c.weightx = 35.0;     c.insets = new insets(20, 5 , 0, 0); //top left bottom right     c.gridx = 1;     add(jenter, c);      //(mod label     leftpar2 = new jlabel("(mod");     leftpar2.setfont(new font("arial", font.plain, 22));      //constraints     c.weightx = 0.01;     c.gridx = 2;     c.insets = new insets(0, 10, 0, 0); //top, left, bottom, right     add(leftpar2, c);      //enter m     nenter = new jformattedtextfield();     nenter.setfont(new font("arial", font.plain, 22));     leftpar2.setlabelfor(nenter);      //constraints     c.weightx = 35.0;     c.insets = new insets(20, 10 , 0, 0); //top, left, bottom, right     c.gridx = 3;     add(nenter, c);      //) label     rightpar2 = new jlabel(")");     rightpar2.setfont(new font("arial", font.plain, 22));      //constraints     c.weightx = 0.01;     c.fill = gridbagconstraints.remainder;     c.gridx = 4;     c.insets = new insets(0, 5, 0, 40); //top, left, bottom, right     add(rightpar2, c);     }//end constructor  } 


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -