+ All Categories
Home > Documents > GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.

GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.

Date post: 31-Mar-2015
Category:
Upload: orion-hollaway
View: 222 times
Download: 2 times
Share this document with a friend
Popular Tags:
23
GridLayout, n*m grid
Transcript
Page 1: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.

GridLayout, n*m grid

Page 2: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.

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.

Components can span multiple columns/rows

Page 4: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.

”Tall” components can create greater vertical distance

Page 5: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.
Page 17: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.
Page 18: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.
Page 19: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.
Page 20: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.
Page 21: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.
Page 22: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.
Page 23: GridLayout, n*m grid. Column width/row height adjusted to fith the widest/highest Component.

GridLayout

GridLayout

FlowLayout


Recommended