Here you can find the source of setWidthPercentageOfScreen(Window window, int widthPercentage)
public static void setWidthPercentageOfScreen(Window window, int widthPercentage)
//package com.java2s; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.Window; import java.util.List; import javax.swing.JComponent; public class Main { public static void setWidthPercentageOfScreen(Window window, int widthPercentage) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int width = (screenSize.width * widthPercentage) / 100; int height = window.getHeight(); window.setSize(width, height);//w ww. jav a2 s .c o m center(window); } public static void setWidthPercentageOfScreen(Window window, double widthPercentage) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int width = (int) (screenSize.width * widthPercentage); int height = window.getHeight(); window.setSize(width, height); center(window); } public static void setSize(Dimension size, JComponent[] components) { for (JComponent component : components) { component.setSize(size); } } public static void setSize(Dimension size, List<JComponent> components) { for (JComponent component : components) { component.setSize(size); } } public static void center(Window window) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = window.getSize(); int x = (screenSize.width - frameSize.width) / 2; int y = (screenSize.height - frameSize.height) / 2; window.setLocation(x, y); } }