Java Example Program / Sample Source Code
import java.awt.Button;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class SettingGapSize {
public static void main(String[] args) {
Frame frame = new Frame("SettingGapSize");
frame.setSize(400, 400);
frame.add(new GridBagLayoutPanel());
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
class GridBagLayoutPanel extends Panel {
public GridBagLayoutPanel() {
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
setLayout(gridbag);
constraints.weightx = constraints.weighty = 10.0;
constraints.fill = GridBagConstraints.NONE;
constraints.ipadx = 30;
constraints.ipady = 10;
// Create a 10 pixel gap between columns 0 and 2
setColumnMinWidth(gridbag, 1, 10);
// Create a 10 pixel gap between rows 0 and 2
setRowMinHeight(gridbag, 1, 10);
addButton("OK", constraints, gridbag);
constraints.weightx = 5.0;
constraints.fill = GridBagConstraints.BOTH;
constraints.ipadx = constraints.ipady = 0;
constraints.insets = new Insets(10, 30, 10, 20);
constraints.gridwidth = GridBagConstraints.RELATIVE;
constraints.gridheight = 2;
// Create a 10 pixel gap between columns 0 and 2
setColumnMinWidth(gridbag, 1, 10);
// Create a 10 pixel gap between rows 0 and 2
setRowMinHeight(gridbag, 1, 10);
addButton("GO", constraints, gridbag);
constraints.insets = new Insets(0, 0, 0, 0);
constraints.gridx = 0;
constraints.fill = GridBagConstraints.NONE;
constraints.ipadx = 30;
constraints.ipady = 10;
constraints.gridwidth = 1;
constraints.gridheight = 1;
// Create a 10 pixel gap between columns 0 and 2
setColumnMinWidth(gridbag, 1, 10);
// Create a 10 pixel gap between rows 0 and 2
setRowMinHeight(gridbag, 1, 10);
addButton("Cancel", constraints, gridbag);
}
private void addButton(String label, GridBagConstraints constraints,
GridBagLayout layout) {
Button button = new Button(label);
layout.setConstraints(button, constraints);
add(button);
}
// Sets the minimum width for column c to be w pixels wide
public void setColumnMinWidth(GridBagLayout gridbag, int c, int w) {
int[] ws = gridbag.columnWidths;
if (ws == null) {
ws = new int[c + 1];
} else if (ws.length < c + 1) {
ws = new int[c + 1];
System.arraycopy(gridbag.columnWidths, 0, ws, 0,
gridbag.columnWidths.length);
}
ws[c] = w;
gridbag.columnWidths = ws;
}
// Sets the minimum height for row r to be h pixels high
public void setRowMinHeight(GridBagLayout gridbag, int r, int h) {
int[] hs = gridbag.rowHeights;
if (hs == null) {
hs = new int[r + 1];
} else if (hs.length < r + 1) {
hs = new int[r + 1];
System.arraycopy(gridbag.rowHeights, 0, hs, 0,
gridbag.rowHeights.length);
}
hs[r] = h;
gridbag.rowHeights = hs;
}
} |
|
|
AWTEventMulticaster
- How To Use AWTEventMulticaster
- add(ActionListener a, ActionListener b) In AWTEventMulticaster
- add(AdjustmentListener a, AdjustmentListener b) In AWTEventMulticaster
- add(ComponentListener a, ComponentListener b) In AWTEventMulticaster
- add(ContainerListener a, ContainerListener b) In AWTEventMulticaster
- add(FocusListener a, FocusListener b) In AWTEventMulticaster
- add(HierarchyBoundsListener a, HierarchyBoundsListener b) In AWTEventMulticaster
- add(HierarchyListener a, HierarchyListener b) In AWTEventMulticaster
- add(InputMethodListener a, InputMethodListener b) In AWTEventMulticaster
- add(ItemListener a, ItemListener b) In AWTEventMulticaster
- add(KeyListener a, KeyListener b) In AWTEventMulticaster
- add(MouseListener a, MouseListener b) In AWTEventMulticaster
- add(MouseMotionListener a, MouseMotionListener b) In AWTEventMulticaster
- add(MouseWheelListener a, MouseWheelListener b) In AWTEventMulticaster
- add(TextListener a, TextListener b) In AWTEventMulticaster
- add(WindowFocusListener a, WindowFocusListener b) In AWTEventMulticaster
- add(WindowListener a, WindowListener b) In AWTEventMulticaster
- add(WindowStateListener a, WindowStateListener b) In AWTEventMulticaster
- addInternal(EventListener a, EventListener b) In AWTEventMulticaster
- remove(ActionListener l, ActionListener oldl) In AWTEventMulticaster
- remove(AdjustmentListener l, AdjustmentListener oldl) In AWTEventMulticaster
- remove(ComponentListener l, ComponentListener oldl) In AWTEventMulticaster
- remove(ContainerListener l, ContainerListener oldl) In AWTEventMulticaster
- remove(EventListener oldl) In AWTEventMulticaster
- remove(FocusListener l, FocusListener oldl) In AWTEventMulticaster
- remove(HierarchyBoundsListener l, HierarchyBoundsListener oldl) In AWTEventMulticaster
- remove(HierarchyListener l, HierarchyListener oldl) In AWTEventMulticaster
- remove(InputMethodListener l, InputMethodListener oldl) In AWTEventMulticaster
- remove(ItemListener l, ItemListener oldl) In AWTEventMulticaster
- remove(KeyListener l, KeyListener oldl) In AWTEventMulticaster
- remove(MouseListener l, MouseListener oldl) In AWTEventMulticaster
- remove(MouseMotionListener l, MouseMotionListener oldl) In AWTEventMulticaster
- remove(MouseWheelListener l, MouseWheelListener oldl) In AWTEventMulticaster
- remove(TextListener l, TextListener oldl) In AWTEventMulticaster
- remove(WindowFocusListener l, WindowFocusListener oldl) In AWTEventMulticaster
- remove(WindowListener l, WindowListener oldl) In AWTEventMulticaster
- remove(WindowStateListener l, WindowStateListener oldl) In AWTEventMulticaster
- removeInternal(EventListener l, EventListener oldl) In AWTEventMulticaster
- save(ObjectOutputStream s, String k, EventListener l) In AWTEventMulticaster
- saveInternal(ObjectOutputStream s, String k) In AWTEventMulticaster
DefaultFocusTraversalPolicy
DefaultKeyboardFocusManager
Graphics
- clipRect(int x, int y, int width, int height) In Graphics
- drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) In Graphics
- drawLine(int x1, int y1, int x2, int y2) In Graphics
- drawOval(int x, int y, int width, int height) In Graphics
- drawPolygon(int[] xPoints, int[] yPoints, int nPoints) In Graphics
- drawRect(int x, int y, int width, int height) In Graphics
- drawString(String str, int x, int y) In Graphics
- fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) In Graphics
- fillOval(int x, int y, int width, int height) In Graphics
- fillPolygon(int[] xPoints, int[] yPoints, int nPoints) In Graphics
- fillRect(int x, int y, int width, int height) In Graphics
- drawImage(Image img, int x, int y, ImageObserver observer) In Graphics
- setColor(Java.awt.Color) In Graphics
- setPaintMode() In Graphics
- setXORMode(Java.awt.Color) In Graphics
- setFont(Java.awt.Font) In Graphics
GraphicsConfiguration
- Using GraphicsConfiguration
- createCompatibleImage(int width, int height) In GraphicsConfiguration
- createCompatibleImage(int width, int height, int transparency) In GraphicsConfiguration
- createCompatibleVolatileImage(int width, int height) In GraphicsConfiguration
- createCompatibleVolatileImage(int width, int height, ImageCapabilities caps) In GraphicsConfiguration
- createCompatibleVolatileImage(int width, int height, ImageCapabilities caps, int transparency) In GraphicsConfiguration
- createCompatibleVolatileImage(int width, int height, int transparency) In GraphicsConfiguration
- getBounds() In GraphicsConfiguration
- getBufferCapabilities() In GraphicsConfiguration
- getColorModel() In GraphicsConfiguration
- getColorModel(int transparency) In GraphicsConfiguration
- getDefaultTransform() In GraphicsConfiguration
- getDevice() In GraphicsConfiguration
- getImageCapabilities() In GraphicsConfiguration
- getNormalizingTransform() In GraphicsConfiguration
- isTranslucencyCapable() In GraphicsConfiguration
MediaTracker
- How To Use MediaTracker
- addImage(Image image, int id) In MediaTracker
- addImage(Image image, int id, int w, int h) In MediaTracker
- checkAll() In MediaTracker
- checkAll(boolean load) In MediaTracker
- checkID(int id) In MediaTracker
- checkID(int id, boolean load) In MediaTracker
- getErrorsAny() In MediaTracker
- getErrorsID(int id) In MediaTracker
- isErrorAny() In MediaTracker
- isErrorID(int id) In MediaTracker
- removeImage(Image image) In MediaTracker
- removeImage(Image image, int id) In MediaTracker
- removeImage(Image image, int id, int width, int height) In MediaTracker
- statusAll(boolean load) In MediaTracker
- statusID(int id, boolean load) In MediaTracker
- waitForAll() In MediaTracker
- waitForAll(long ms) In MediaTracker
- waitForID(int id) In MediaTracker
- waitForID(int id, long ms) In MediaTracker
|
|
|
|