Java JDesktopPane tileHorizontal(JDesktopPane desktop)

Here you can find the source of tileHorizontal(JDesktopPane desktop)

Description

tile Horizontal

License

Open Source License

Declaration

public static final void tileHorizontal(JDesktopPane desktop) 

Method Source Code

//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

import java.awt.Dimension;

import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;

public class Main {
    public static final void tileHorizontal(JDesktopPane desktop) {
        int _resizableCnt = 0;
        JInternalFrame _allFrames[] = desktop.getAllFrames();
        for (int _x = 0; _x < _allFrames.length; _x++) {
            JInternalFrame _frame = _allFrames[_x];
            if ((_frame.isVisible()) && (!_frame.isIcon())) {
                if (!_frame.isResizable()) {
                    try {
                        _frame.setMaximum(false);
                    } catch (Exception _e) {
                        // OK, to take no action here
                    }// w  w  w  .  j  a v a 2s.  c  o  m
                }
                if (_frame.isResizable()) {
                    _resizableCnt++;
                }
            }
        } // End for
        int _width = desktop.getBounds().width;
        int _height = arrangeIcons(desktop);
        if (_resizableCnt != 0) {
            int _fHeight = _height / _resizableCnt;
            int _yPos = 0;
            for (int _x = 0; _x < _allFrames.length; _x++) {
                JInternalFrame _frame = _allFrames[_x];
                if ((_frame.isVisible()) && (_frame.isResizable()) && (!_frame.isIcon())) {
                    _frame.setSize(_width, _fHeight);
                    _frame.setLocation(0, _yPos);
                    _yPos += _fHeight;
                }
            } // End for
        }
    }

    public static final int arrangeIcons(JDesktopPane desktop) {
        int _iconCnt = 0;
        JInternalFrame _allFrames[] = desktop.getAllFrames();
        for (int _x = 0; _x < _allFrames.length; _x++) {
            if ((_allFrames[_x].isVisible()) && (_allFrames[_x].isIcon())) {
                _iconCnt++;
            }
        }
        int _height = desktop.getBounds().height;
        int _yPos = _height;
        if (_iconCnt != 0) {
            int _width = desktop.getBounds().width;
            int _xPos = 0;
            for (int _x = 0; _x < _allFrames.length; _x++) {
                JInternalFrame _frame = _allFrames[_x];
                if ((_frame.isVisible()) && (_frame.isIcon())) {
                    Dimension _dim = _frame.getDesktopIcon().getSize();
                    int _iWidth = _dim.width;
                    int _iHeight = _dim.height;
                    if (_yPos == _height) {
                        _yPos = _height - _iHeight;
                    }
                    if ((_xPos + _iWidth > _width) && (_xPos != 0)) {
                        _xPos = 0;
                        _yPos -= _iHeight;
                    }
                    _frame.getDesktopIcon().setLocation(_xPos, _yPos);
                    _xPos += _iWidth;
                } // End if
            } // End for
        } // End if
        return (_yPos);
    }
}

Related

  1. arrangeIcons(JDesktopPane desktop)
  2. arrangeMinifiedWindows(JDesktopPane desktop)
  3. cascade(JDesktopPane desktopPane, int layer)
  4. makeCenter(JDesktopPane desktop)
  5. moveOff(JDesktopPane desktop)
  6. tileVertical(JDesktopPane desktop)