Package org.jdesktop.application
Class View
- java.lang.Object
-
- org.jdesktop.application.AbstractBean
-
- org.jdesktop.application.View
-
- Direct Known Subclasses:
FrameView
public class View extends AbstractBean
A View encapsulates a top-level Application GUI component, like a JFrame or an Applet, and its main GUI elements: a menu bar, tool bar, component, and a status bar. All of the elements are optional (although a View without a main component would be unusual). Views have aJRootPane, which is the root component for all of the Swing Window types as well as JApplet. Setting a View property, likemenuBarortoolBar, just adds a component to the rootPane in a way that's defined by the View subclass. By default the View elements are arranged in a conventional way:-
menuBar- becomes the rootPane's JMenuBar -
toolBar- added toBorderLayout.NORTHof the rootPane's contentPane -
component- added toBorderLayout.CENTERof the rootPane's contentPane -
statusBar- added toBorderLayout.SOUTHof the rootPane's contentPane
To show or hide a View you call the corresponding Application methods. Here's a simple example:
class MyApplication extends SingleFrameApplication { @ppOverride protected void startup() { View view = getMainView(); view.setComponent(createMainComponent()); view.setMenuBar(createMenuBar()); show(view); } }The advantage of Views over just configuring a JFrame or JApplet directly, is that a View is more easily moved to an alternative top level container, like a docking framework.
- See Also:
JRootPane,Application.show(View),Application.hide(View)
-
-
Constructor Summary
Constructors Constructor Description View(Application application)Construct an empty View object for the specified Application.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ApplicationgetApplication()TheApplicationthat's responsible for showing/hiding this View.javax.swing.JComponentgetComponent()The main {JComponent} for this View.ApplicationContextgetContext()TheApplicationContextfor theApplicationthat's responsible for showing/hiding this View.javax.swing.JMenuBargetMenuBar()The main {JMenuBar} for this View.ResourceMapgetResourceMap()TheResourceMapfor this View.javax.swing.JRootPanegetRootPane()TheJRootPanefor this View.javax.swing.JComponentgetStatusBar()javax.swing.JToolBargetToolBar()java.util.List<javax.swing.JToolBar>getToolBars()voidsetComponent(javax.swing.JComponent component)Set the single main Component for this View.voidsetMenuBar(javax.swing.JMenuBar menuBar)voidsetStatusBar(javax.swing.JComponent statusBar)voidsetToolBar(javax.swing.JToolBar toolBar)voidsetToolBars(java.util.List<javax.swing.JToolBar> toolBars)-
Methods inherited from class org.jdesktop.application.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Constructor Detail
-
View
public View(Application application)
Construct an empty View object for the specified Application.- Parameters:
application- the Application responsible for showing/hiding this View- See Also:
Application.show(View),Application.hide(View)
-
-
Method Detail
-
getApplication
public final Application getApplication()
TheApplicationthat's responsible for showing/hiding this View.- Returns:
- the Application that owns this View
- See Also:
getContext(),Application.show(View),Application.hide(View)
-
getContext
public final ApplicationContext getContext()
TheApplicationContextfor theApplicationthat's responsible for showing/hiding this View. This method is just shorthand forgetApplication().getContext().- Returns:
- the Application that owns this View
- See Also:
getApplication(),Application.show(View),Application.hide(View)
-
getResourceMap
public ResourceMap getResourceMap()
TheResourceMapfor this View. This method is just shorthand forgetContext().getResourceMap(getClass(), View.class).- Returns:
- The
ResourceMapfor this View - See Also:
getContext()
-
getRootPane
public javax.swing.JRootPane getRootPane()
TheJRootPanefor this View. All of the components for this View must be added to its rootPane. Most applications will do so by setting the View'scomponent,menuBar,toolBar, andstatusBarproperties.- Returns:
- The
rootPanefor this View - See Also:
setComponent(javax.swing.JComponent),setMenuBar(javax.swing.JMenuBar),setToolBar(javax.swing.JToolBar),setStatusBar(javax.swing.JComponent)
-
getComponent
public javax.swing.JComponent getComponent()
The main {JComponent} for this View.- Returns:
- The
componentfor this View - See Also:
setComponent(javax.swing.JComponent)
-
setComponent
public void setComponent(javax.swing.JComponent component)
Set the single main Component for this View. It's added to theBorderLayout.CENTERof the rootPane's contentPane. If the component property was already set, the old component is removed first.This is a bound property. The default value is null.
- Parameters:
component- Thecomponentfor this View- See Also:
getComponent()
-
getMenuBar
public javax.swing.JMenuBar getMenuBar()
The main {JMenuBar} for this View.- Returns:
- The
menuBarfor this View - See Also:
setMenuBar(javax.swing.JMenuBar)
-
setMenuBar
public void setMenuBar(javax.swing.JMenuBar menuBar)
-
getToolBars
public java.util.List<javax.swing.JToolBar> getToolBars()
-
setToolBars
public void setToolBars(java.util.List<javax.swing.JToolBar> toolBars)
-
getToolBar
public final javax.swing.JToolBar getToolBar()
-
setToolBar
public final void setToolBar(javax.swing.JToolBar toolBar)
-
getStatusBar
public javax.swing.JComponent getStatusBar()
-
setStatusBar
public void setStatusBar(javax.swing.JComponent statusBar)
-
-