Java Utililty Methods JFrame

List of utility methods to do JFrame

Description

The list of methods to do JFrame are organized into topic(s).

Method

voidsmartSetBounds(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) {
...
voidstaggerOpenedFrames(List frames)
stagger Opened Frames
JFrame previous = null;
if (frames != null && frames.size() > 1) {
    for (JFrame frame : frames) {
        if (frame == null) {
            continue;
        if (previous != null) {
            Point pt = previous.getLocation();
...
voidstorePrefsFrame(Preferences node, JFrame frame)
Stores a JFrame size, location and state to the given Preferences node.
storePrefsComponent(node, frame);
node.putInt(PREFK_STATE, frame.getExtendedState());
voidtellUserToChoose(JFrame jFrame)
tell User To Choose
JOptionPane.showMessageDialog(jFrame, "Please choose a game!");
voidterminarPrograma(JFrame f)
terminar Programa
f.setVisible(false);
f.dispose();
System.exit(0);
voidtoFront(final JFrame window)
Bring a window to the front
WindowFocusListener listener = new WindowFocusListener() {
    public void windowGainedFocus(WindowEvent e) {
        window.setAlwaysOnTop(true);
    public void windowLostFocus(WindowEvent e) {
        window.setAlwaysOnTop(false);
        window.removeWindowFocusListener(this);
};
window.addWindowFocusListener(listener);
window.toFront();
SwingUtilities.invokeLater(new Runnable() {
    public void run() {
        window.requestFocus();
});
voidtoFront(JFrame frame)
to Front
if (frame.getExtendedState() >= Frame.MAXIMIZED_BOTH) {
    frame.setExtendedState(Frame.MAXIMIZED_BOTH);
} else if (frame.getExtendedState() > Frame.NORMAL) {
    frame.setExtendedState(Frame.NORMAL);
frame.setVisible(true);
voidtoFrontHack(JFrame theParent, JFrame theFrame)
Moves a frame in front of another frame
if (theFrame.getState() == Frame.ICONIFIED) {
    theFrame.setState(Frame.NORMAL);
} else {
    Point origPos = theFrame.getLocation();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    theFrame.setLocation(screenSize.width + theParent.getWidth(),
            screenSize.height + theParent.getHeight());
    theFrame.setState(Frame.ICONIFIED);
...
voidtoggleFrame(JFrame frame)
toggle Frame
if (frame == null) {
    return;
frame.setVisible(!frame.isVisible());
voidtoggleOsXFullScreen(JFrame frame)
toggle Os X Full Screen
try {
    Class<?> app = Class.forName("com.apple.eawt.Application");
    Method m = app.getDeclaredMethod("getApplication", new Class[0]);
    Object application = m.invoke(null, new Object[0]);
    m = app.getDeclaredMethod("requestToggleFullScreen", Window.class);
    m.invoke(application, frame);
} catch (Exception ex) {