Here you can find the source of storePrefsFrame(Preferences node, JFrame frame)
Parameter | Description |
---|---|
node | the Preferences node |
frame | the frame whose size and location must be saved |
public static void storePrefsFrame(Preferences node, JFrame frame)
//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()); } }