GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.
-
Upload
orion-hollaway -
Category
Documents
-
view
225 -
download
2
Transcript of GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.
![Page 1: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/1.jpg)
GridLayout, n*m grid
![Page 2: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/2.jpg)
Column width/row height adjusted to fith the widest/highest Component
![Page 3: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/3.jpg)
Components can span multiple columns/rows
![Page 4: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/4.jpg)
”Tall” components can create greater vertical distance
![Page 5: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/5.jpg)
Components will keep their original size as default
![Page 6: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/6.jpg)
Components can also be stretched to fill the available space
![Page 7: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/7.jpg)
Components can be placed towards any side of the cell
![Page 8: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/8.jpg)
Hei
Hei
Hei
import javax.swing.*;import java.awt.*;
public class Test extends JPanel {
public void lagLayout () { GridBagLayout layout = new GridBagLayout (); setLayout (layout); GridBagConstraints gbc = new GridBagConstraints ();
![Page 9: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/9.jpg)
Hei
Hei
Hei
gbc.fill = GridBagConstraints.NONE;gbc.insets = new Insets (2, 2, 2, 2);
import javax.swing.*;import java.awt.*;
public class Test extends JPanel {
public void lagLayout () { GridBagLayout layout = new GridBagLayout (); setLayout (layout); GridBagConstraints gbc = new GridBagConstraints ();
![Page 10: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/10.jpg)
Hei
Hei
Hei
gbc.gridx = 0;gbc.gridy = 0;gbc.gridwidth = 1;gbc.gridheight = 1;JLabel label1 = new JLabel ("Hei");layout.setConstraints (label1, gbc);add (label1);
import javax.swing.*;import java.awt.*;
public class Test extends JPanel {
public void lagLayout () { GridBagLayout layout = new GridBagLayout (); setLayout (layout); GridBagConstraints gbc = new GridBagConstraints (); gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets (2, 2, 2, 2);
![Page 11: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/11.jpg)
Hei
Hei
Hei
gbc.gridy = 6;gbc.gridwidth = 3;gbc.anchor = GridBagConstraints.WEST;JTextField text2 = new JTextField ("Dette er en test");layout.setConstraints (text2, gbc);add (text2);
import javax.swing.*;import java.awt.*;
public class Test extends JPanel {
public void lagLayout () { GridBagLayout layout = new GridBagLayout (); setLayout (layout); GridBagConstraints gbc = new GridBagConstraints (); gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets (2, 2, 2, 2); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; JLabel label1 = new JLabel ("Hei"); layout.setConstraints (label1, gbc); add (label1);
![Page 12: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/12.jpg)
Hei
Hei
Hei
gbc.gridy = 4;gbc.gridx = 2;gbc.gridwidth = 2;gbc.fill = GridBagConstraints.HORIZONTAL;JButton button2 = new JButton (”Fin knapp");layout.setConstraints (button2, gbc);add (button2);
GridBagLayout layout = new GridBagLayout (); setLayout (layout); GridBagConstraints gbc = new GridBagConstraints (); gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets (2, 2, 2, 2); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; JLabel label1 = new JLabel ("Hei"); layout.setConstraints (label1, gbc); add (label1); gbc.gridy = 6; gbc.gridwidth = 3; gbc.anchor = GridBagConstraints.WEST; JTextField text2 = new JTextField ("Dette er en test"); layout.setConstraints (text2, gbc); add (text2);
![Page 13: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/13.jpg)
Hei
Hei
Hei
gbc.gridy = 5;gbc.gridx = 1;gbc.fill = GridBagConstraints.BOTH;JTextArea text3 = new JTekstArea (5,40);layout.setConstraints (text3, gbc);add (text3);
gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; JLabel label1 = new JLabel ("Hei"); layout.setConstraints (label1, gbc); add (label1); gbc.gridy = 6; gbc.gridwidth = 3; gbc.anchor = GridBagConstraints.WEST; JTextField text2 = new JTextField ("Dette er en test"); layout.setConstraints (text2, gbc); add (text2); gbc.gridy = 4; gbc.gridx = 2; gbc.gridwidth = 2; gbc.fill = GridBagConstraints.HORIZONTAL; JButton button2 = new JButton (”Fin knapp"); layout.setConstraints (button2, gbc); add (button2);
![Page 14: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/14.jpg)
Hei
Hei
Hei
Same for the rest of the components.::
}
gbc.gridy = 6; gbc.gridwidth = 3; gbc.anchor = GridBagConstraints.WEST; JTextField text2 = new JTextField ("Dette er en test"); layout.setConstraints (text2, gbc); add (text2); gbc.gridy = 4; gbc.gridx = 2; gbc.gridwidth = 2; gbc.fill = GridBagConstraints.HORIZONTAL; JButton button2 = new JButton (”Fin knapp"); layout.setConstraints (button2, gbc); add (button2); gbc.gridy = 5; gbc.gridx = 1; gbc.fill = GridBagConstraints.BOTH; JTextArea text3 = new JTekstArea (5,40); layout.setConstraints (text3, gbc); add (text3);
![Page 15: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/15.jpg)
public static void main (String args[]) { Test t = new Test (); t.lagLayout (); JFrame f = new JFrame (); f.getContentPane ().add (t); f.pack (); f.setVisible (true); }}
Hei
Hei
Hei
![Page 16: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/16.jpg)
![Page 17: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/17.jpg)
![Page 18: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/18.jpg)
![Page 19: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/19.jpg)
![Page 20: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/20.jpg)
![Page 21: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/21.jpg)
![Page 22: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/22.jpg)
![Page 23: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.](https://reader035.fdocuments.in/reader035/viewer/2022062620/551a6c3d550346545e8b5f23/html5/thumbnails/23.jpg)
GridLayout
GridLayout
FlowLayout