Java JFrame storePrefsFrame(Preferences node, JFrame frame)

Here you can find the source of storePrefsFrame(Preferences node, JFrame frame)

Description

Stores a JFrame size, location and state to the given Preferences node.

License

Apache License

Parameter

Parameter Description
node the Preferences node
frame the frame whose size and location must be saved

Declaration

public static void storePrefsFrame(Preferences node, JFrame frame) 

Method Source Code


//package com.java2s;
/*/*from  w  w  w .  j a va2s . c  om*/
 * Copyright 2013 Alessandro Falappa.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.Component;

import java.util.prefs.Preferences;

import javax.swing.JFrame;

public class Main {
    private static final String PREFK_LOC_X = "LocX";
    private static final String PREFK_LOC_Y = "LocY";
    private static final String PREFK_WIDTH = "Width";
    private static final String PREFK_HEIGHT = "Height";
    private static final String PREFK_STATE = "State";

    /**
     * Stores a {@link JFrame} size, location and state to the given {@link Preferences} node.
     *
     * @param node the Preferences node
     * @param frame the frame whose size and location must be saved
     */
    public static void storePrefsFrame(Preferences node, JFrame frame) {
        storePrefsComponent(node, frame);
        node.putInt(PREFK_STATE, frame.getExtendedState());
    }

    /**
     * Stores a {@link Component} size and location to the given {@link Preferences} node.
     *
     * @param node the Preferences node
     * @param comp the component whose size and location must be saved
     */
    public static void storePrefsComponent(Preferences node, Component comp) {
        node.putInt(PREFK_LOC_X, comp.getX());
        node.putInt(PREFK_LOC_Y, comp.getY());
        node.putInt(PREFK_WIDTH, comp.getWidth());
        node.putInt(PREFK_HEIGHT, comp.getHeight());
    }
}

Related

  1. setWindowListenerDispose(JFrame frame)
  2. setWindowRightSide(final JFrame frame)
  3. setWinVisible(final JFrame win, final boolean vis)
  4. smartSetBounds(JFrame frame)
  5. staggerOpenedFrames(List frames)
  6. tellUserToChoose(JFrame jFrame)
  7. terminarPrograma(JFrame f)
  8. toFront(final JFrame window)
  9. toFront(JFrame frame)