All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pepsoft.worldpainter.util.LayoutUtils Maven / Gradle / Ivy

There is a newer version: 2.23.2
Show newest version
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.pepsoft.worldpainter.util;

import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.util.Collection;
import java.util.Iterator;

/**
 *
 * @author SchmitzP
 */
public final class LayoutUtils {
    private LayoutUtils() {
        // Prevent instantiation
    }
    
    public static void addRowOfComponents(Container container, GridBagConstraints constraints, Collection components) {
        for (Iterator i = components.iterator(); i.hasNext(); ) {
            Component component = i.next();
            if (i.hasNext()) {
                // Not the last component
                constraints.gridwidth = 1;
                constraints.weightx = 0.0;
            } else {
                // Last component
                constraints.gridwidth = GridBagConstraints.REMAINDER;
                constraints.weightx = 1.0;
            }
            container.add(component, constraints);
        }
    }    

    public static void insertRowOfComponents(Container container, GridBagConstraints constraints, int index, Collection components) {
        for (Iterator i = components.iterator(); i.hasNext(); ) {
            Component component = i.next();
            if (i.hasNext()) {
                // Not the last component
                constraints.gridwidth = 1;
                constraints.weightx = 0.0;
            } else {
                // Last component
                constraints.gridwidth = GridBagConstraints.REMAINDER;
                constraints.weightx = 1.0;
            }
            container.add(component, constraints, index++);
        }
    }    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy