All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jdesktop.application.FrameView Maven / Gradle / Ivy

There is a newer version: 1.9.2
Show newest version
/*
 * Copyright (C) 2006 Sun Microsystems, Inc. All rights reserved. Use is
 * subject to license terms.
 */
package org.jdesktop.application;

import java.awt.Image;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JRootPane;

import static org.jdesktop.application.Application.KEY_APPLICATION_ICON;
import static org.jdesktop.application.Application.KEY_APPLICATION_TITLE;

public class FrameView extends View {
    public static final String MAIN_FRAME_NAME = "mainFrame";

    private static final Logger logger = Logger.getLogger(FrameView.class.getName());
    private JFrame frame = null;

    public FrameView(Application application) {
        super(application);
    }

    /**
     * Return the JFrame used to show this View
     * 
     * 

* This method may be called at any time; the JFrame is created lazily * and cached. For example: *

     *  @Override protected void startup() {
     *     getFrame().setJMenuBar(createMenuBar());
     *     show(createMainPanel());
     * }
     * 
* * @return this application's main frame */ public JFrame getFrame() { if (frame == null) { ResourceMap resourceMap = getContext().getResourceMap(); String title = resourceMap.getString(KEY_APPLICATION_TITLE); frame = new JFrame(title); frame.setName(MAIN_FRAME_NAME); if (resourceMap.containsKey(KEY_APPLICATION_ICON)) { Image icon = resourceMap.getImageIcon(KEY_APPLICATION_ICON).getImage(); frame.setIconImage(icon); } } return frame; } /** * Sets the JFrame use to show this View *

* This method should be called from the startup method by a * subclass that wants to construct and initialize the main frame * itself. Most applications can rely on the fact that {code * getFrame} lazily constructs the main frame and initializes * the {@code frame} property. *

* If the main frame property was already initialized, either * implicitly through a call to {@code getFrame} or by * explicitly calling this method, an IllegalStateException is * thrown. If {@code frame} is null, an IllegalArgumentException * is thrown. *

* This property is bound. * * * * @param frame the new value of the frame property * @see #getFrame */ public void setFrame(JFrame frame) { if (frame == null) { throw new IllegalArgumentException("null JFrame"); } if (this.frame != null) { throw new IllegalStateException("frame already set"); } this.frame = frame; firePropertyChange("frame", null, this.frame); } @Override public JRootPane getRootPane() { return getFrame().getRootPane(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy