java - How does GridBagLayout functions such as gridwidth/height and gridx/y work to scale the size of the GUI? -


i introduced gridbaglayout substitute vanilla jpanel layout, having trouble working functions gridwidth/height , gridx/y. not sure how work in changing size of gui , positions of buttons. below code professor gave me use reference, , tried fiddling numbers results never turned out expected happen, , not sure why.

edit 1: clarify, wondering how gridwidth, gridheight, gridx, , gridy functions work resize gui , position buttons' locations.

import java.awt.*; import javax.swing.*;  class bar1 {      public static void main(string[] args) {         jframe frame = new jframe();         jpanel panel = new jpanel();         panel.setlayout(new gridbaglayout());         gridbagconstraints c = new gridbagconstraints();         frame.setdefaultcloseoperation(jframe.exit_on_close);          c.gridx=0;         c.gridy=0;         c.gridwidth=2;         c.gridheight=1;         c.weightx = 2;         c.weighty = 1;         c.fill = gridbagconstraints.both;         jbutton b = new jbutton("hello");         panel.add(b, c);         c.gridx=0;         c.gridy=1;         c.gridwidth=1;         c.gridheight=1;         jbutton b2 = new jbutton("world");         panel.add(b2, c);         c.gridx=1;         c.gridy=1;         c.gridwidth=1;         c.gridheight=1;         jbutton b3 = new jbutton("!!!");         panel.add(b3, c);          frame.add(panel);         frame.pack();         frame.setvisible(true);      } } 


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -