Example usage for javax.swing JComboBox getBounds

List of usage examples for javax.swing JComboBox getBounds

Introduction

In this page you can find the example usage for javax.swing JComboBox getBounds.

Prototype

public Rectangle getBounds() 

Source Link

Document

Gets the bounds of this component in the form of a Rectangle object.

Usage

From source file:org.eclipse.jubula.rc.swing.tester.adapter.JComboBoxAdapter.java

/**
 * @return a rectangle, where the arrow icon is expected.
 *///from   w  ww  .j ava  2 s .  c  o  m
private Rectangle findArrowIconArea() {
    JComboBox comboBox = m_comboBox;
    Component editor = getComboBoxEditorComponent(comboBox);
    Rectangle r = null;
    if (editor == null) {
        throw new StepExecutionException("could not find editor", //$NON-NLS-1$
                EventFactory.createActionError(TestErrorEvent.COMP_NOT_FOUND));
    }
    Rectangle ra[] = SwingUtilities.computeDifference(comboBox.getBounds(), editor.getBounds());
    if ((ra == null) || (ra.length < 1)) {
        throw new StepExecutionException("could not arrow icon", //$NON-NLS-1$
                EventFactory.createActionError(TestErrorEvent.COMP_NOT_FOUND));
    }
    r = ra[0];
    // find the largest area of the returned rectangles.
    double bestAreaIndex = Double.MAX_VALUE;
    for (int i = 0; i < ra.length; i++) {
        if ((ra[i].height > 0) && (ra[i].width > 0)) {
            double areaIndex = ((double) ra[i].width) / ra[i].height - 1.0;
            if (areaIndex < 0) {
                areaIndex *= (-1);
            }
            if (areaIndex < bestAreaIndex) {
                bestAreaIndex = areaIndex;
                r = ra[i];
            }
        }
    }
    return r;
}