[4993] in java-interest
RE: problem with GridBagLayout
daemon@ATHENA.MIT.EDU (Cay Horstmann)
Thu Jan 25 12:04:36 1996
From: horstman@jupiter.SJSU.EDU (Cay Horstmann)
To: markus@bali.informatik.rwth-aachen.de ("'Markus Schunck'")
Cc: java-interest@java.sun.com ("'java-interest@java.sun.com'")
Date: Wed, 24 Jan 96 12:38:52 EST
Here is a font dialog example using the grid bag layout
(shameless commercial plug--it is from Gary Cornell's and my book "Core
Java",
to be published by SunSoft Press/Prentice Hall in March).
Look at the add helper function--I just use numbers for x and y, none of
that RELATIVE and REMAINING stuff whose significance nobody could explain
to me.
Cay
import java.awt.*;
public class FontDialog extends Frame
{ private void add(Component c, GridBagLayout gbl, GridBagConstraints gbc,
int x, int y, int w, int h)
{ gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = w;
gbc.gridheight = h;
gbl.setConstraints(c, gbc);
add(c);
}
public FontDialog()
{ super("FontDialog");
GridBagLayout gbl = new GridBagLayout();
setLayout(gbl);
style = new List(4, false);
style.addItem("Times Roman");
style.addItem("Helvetica");
style.addItem("Courier");
style.addItem("Zapf Dingbats");
style.addItem("Dialog");
style.addItem("DialogInput");
Checkbox bold = new Checkbox("Bold");
Checkbox italic = new Checkbox("Italic");
Label label = new Label("Size: ");
TextField size = new TextField();
TextField sample = new TextField();
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 20;
gbc.weighty = 100;
add(style, gbl, gbc, 0, 0, 1, 3);
gbc.weightx = 100;
gbc.fill = GridBagConstraints.NONE;
gbc.anchor = GridBagConstraints.CENTER;
add(bold, gbl, gbc, 1, 0, 2, 1);
add(italic, gbl, gbc, 1, 1, 2, 1);
add(label, gbl, gbc, 1, 2, 1, 1);
gbc.fill = GridBagConstraints.HORIZONTAL;
add(size, gbl, gbc, 2, 2, 1, 1);
gbc.anchor = GridBagConstraints.SOUTH;
gbc.weighty = 0;
add(sample, gbl, gbc, 0, 3, 4, 1);
}
public boolean handleEvent(Event evt)
{ if (evt.id == Event.WINDOW_DESTROY) System.exit(0);
return super.handleEvent(evt);
}
public boolean action(Event evt, Object arg)
{ if (evt.target.equals(bold) || evt.target.equals(italic))
{ int m = (bold.getState() ? Font.BOLD : 0) + (italic.getState() ?
Font.ITALIC : 0);
}
else return super.action(evt, arg);
return true;
}
public static void main(String[] args)
{ Frame f = new FontDialog();
f.resize(250, 150);
f.show();
}
List style;
Checkbox bold;
Checkbox italic;
TextField size;
TextField sample;
}
----------
From: Markus Schunck[SMTP:markus@bali.informatik.rwth-aachen.de]
Sent: Wednesday, January 24, 1996 9:05 AM
To: horstman@jupiter.SJSU.EDU
Subject: problem with GridBagLayout
Hi,
I'm at the moment at the point that you were some time ago, i.e. I dont
understand how GridBagLayout works. You mentioned that you " tried the much
simpler scheme of setting x and y, width and heightto their actual values
rather than havingthe grid bag layout recover them from my hints, and it
seems to work just fine."
Would You please send me an example of this ?
Thank you
markus
email:markus@i4.informatik.rwth-aachen.de
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com