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

java.com.generationjava.awt.HorizontalFlowLayout Maven / Gradle / Ivy

The newest version!
// HorizontalFlowLayout.java
package com.generationjava.awt;

import java.awt.LayoutManager;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Container;
import java.awt.Insets;

/**
 * Like FlowLayout, but works like VerticalFlowLayout.
 * Based on a VerticalFlowLayout in the Java Pitfalls book - 0471361747.
 */
public class HorizontalFlowLayout implements LayoutManager {

    private int horizGap;

    public HorizontalFlowLayout() {
        this(2);
    }

    public HorizontalFlowLayout(int gap) {
        horizGap = gap;
    }

    public int getHorizontalGap() {
        return horizGap;
    }

    // implement LayoutManager
    public void addLayoutComponent(String name, Component comp) {
    }
    public void removeLayoutComponent(Component comp) {
    }
    
    public Dimension preferredLayoutSize(Container parent) {
        return getLayoutSize(parent,false);
    }
    public Dimension minimumLayoutSize(Container parent) {
        return getLayoutSize(parent,true);
    }
    
    private Dimension getLayoutSize(Container parent, boolean min) {
        int count = parent.getComponentCount();
        Dimension size = new Dimension(0,0);
        for(int i=0;i 0) {
                    w += (w * xsWidth / required.width);
                }
                
                c.setBounds(x,y,w,h);
                x += (w + getHorizontalGap());
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy