Java JFrame smartSetBounds(JFrame frame)

Here you can find the source of smartSetBounds(JFrame frame)

Description

License

Open Source License

Parameter

Parameter Description
frame a parameter

Declaration

public static void smartSetBounds(JFrame frame) 

Method Source Code


//package com.java2s;
/*/*ww  w.j a  v  a2 s  .  com*/
 * @(#)SwingUtils.java   2010.01.25 at 11:23:37 PST
 *
 * Copyright 2009 MBARI
 *
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.*;

import javax.swing.*;

public class Main {
    /**
     * <p><!-- Method description --></p>
     *
     *
     * @param frame
     */
    public static void smartSetBounds(JFrame frame) {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int width = 500;
        int height = 500;
        if (screenSize.height <= 600) {
            height = (int) (screenSize.height * .95);
        } else if (screenSize.height <= 1000) {
            height = (int) (screenSize.height * .90);
        } else if (screenSize.height <= 1200) {
            height = (int) (screenSize.height * .85);
        } else {
            height = (int) (screenSize.height * .80);
        }

        if (screenSize.width <= 1000) {
            width = (int) (screenSize.width * .95);
        } else if (screenSize.width <= 1200) {
            width = (int) (screenSize.width * .90);
        } else if (screenSize.width <= 1600) {
            width = (int) (screenSize.width * .85);
        } else {
            width = (int) (screenSize.width * .80);
        }

        frame.setBounds(0, 0, width, height);
    }
}

Related

  1. setPanel(JPanel parent, JPanel child, JFrame f)
  2. setPersistentExtendedStateMask(JFrame frame, int persistentExtendedStateMask)
  3. setWindowListenerDispose(JFrame frame)
  4. setWindowRightSide(final JFrame frame)
  5. setWinVisible(final JFrame win, final boolean vis)
  6. staggerOpenedFrames(List frames)
  7. storePrefsFrame(Preferences node, JFrame frame)
  8. tellUserToChoose(JFrame jFrame)
  9. terminarPrograma(JFrame f)