FileDocCategorySizeDatePackage
Utility.javaAPI DocExample4388Wed Apr 19 11:19:04 BST 2000None

Utility

public class Utility extends Object

Fields Summary
public static final Font
titleFont
public static final Font
labelFont
public static final Font
choiceFont
public static final Font
editFont
public static final Font
creditFont
private static Locale[]
localeList
Constructors Summary
Methods Summary
public static voidfixGrid(java.awt.Container cont, int columns)
Provides easy way to use basic functions of GridBagLayout, without the complications. After building a panel, and inserting all the subcomponents, call this to lay it out in the desired number of columns.


                                               
           
        GridBagLayout gridbag = new GridBagLayout();
        cont.setLayout(gridbag);

        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.VERTICAL;
        c.weightx = 1.0;
        c.insets = new Insets(2,2,2,2);

        Component[] components = cont.getComponents();
        for (int i = 0; i < components.length; ++i) {
            int colNumber = i%columns;
            c.gridwidth = 1;    // default
            if ((i%columns) == columns - 1)
                c.gridwidth = GridBagConstraints.REMAINDER;    // last in grid
            if (components[i] instanceof Label) {
                switch (((Label)components[i]).getAlignment()) {
                case Label.CENTER: c.anchor = GridBagConstraints.CENTER; break;
                case Label.LEFT: c.anchor = GridBagConstraints.WEST; break;
                case Label.RIGHT: c.anchor = GridBagConstraints.EAST; break;
                }
            }
            gridbag.setConstraints(components[i], c);
        }

    
public static java.util.Locale[]getG7Locales()
Get the G7 locale list for demos.

        return localeList;
    
public static voidsetInsets(java.awt.Container cont, java.awt.Component comp, java.awt.Insets insets)
Provides easy way to change the spacing around an object in a GridBagLayout. Call AFTER fixGridBag, passing in the container, the component, and the new insets.

        GridBagLayout gbl = (GridBagLayout)cont.getLayout();
        GridBagConstraints g = gbl.getConstraints(comp);
        g.insets = insets;
        gbl.setConstraints(comp,g);
    
public static voidsetText(java.awt.TextComponent area, java.lang.String newText)

        String foo = area.getText();
        if (foo.equals(newText)) return;
        area.setText(newText);