Package org.jdesktop.application
Class View
java.lang.Object
org.jdesktop.application.AbstractBean
org.jdesktop.application.View
- Direct Known Subclasses:
FrameView
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 a
JRootPane, which
is the root component for all of the Swing Window types as well as JApplet.
Setting a View property, like menuBar or toolBar, 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:
-
Constructor Summary
ConstructorsConstructorDescriptionView(Application application) Construct an empty View object for the specified Application. -
Method Summary
Modifier and TypeMethodDescriptionfinal ApplicationReturns theApplicationthat's responsible for showing/hiding this View.Returns the mainJComponentfor this View.final ApplicationContextGets theApplicationContextfor theApplicationthat's responsible for showing/hiding this View.Returns the mainJMenuBarfor this View.GetsResourceMapfor this View.Gets theJRootPanefor this View.Returns the Status bar for this View.final JToolBarGets the first tool bar for this ViewReturns the list of tool bars for this ViewvoidsetComponent(JComponent component) Sets the single main Component for this View.voidsetMenuBar(JMenuBar menuBar) Sets the menu bar for this View.voidsetStatusBar(JComponent statusBar) Sets the status bar for this View.final voidsetToolBar(JToolBar toolBar) Sets the only tool bar for this View.voidsetToolBars(List<JToolBar> toolBars) Sets the tool bars for this ViewMethods inherited from class org.jdesktop.application.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Constructor Details
-
View
Construct an empty View object for the specified Application.- Parameters:
application- the Application responsible for showing/hiding this View- See Also:
-
-
Method Details
-
getApplication
Returns theApplicationthat's responsible for showing/hiding this View.- Returns:
- the Application that owns this View
- See Also:
-
getContext
Gets 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:
-
getResourceMap
GetsResourceMapfor this View. This method invokesgetContext().getResourceMap(getClass(), View.class). The result is cached.- Returns:
- The
ResourceMapfor this View - See Also:
-
getRootPane
Gets 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:
-
getComponent
Returns the mainJComponentfor this View.- Returns:
- The
componentfor this View - See Also:
-
setComponent
Sets 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:
-
getMenuBar
Returns the mainJMenuBarfor this View.- Returns:
- The
menuBarfor this View - See Also:
-
setMenuBar
Sets the menu bar for this View.This is a bound property. The default value is null.
- Parameters:
menuBar- ThemenuBarfor this View- See Also:
-
getToolBars
Returns the list of tool bars for this View- Returns:
- The list of tool bars
-
setToolBars
Sets the tool bars for this ViewThis is a bound property. The default value is an empty list.
- Parameters:
toolBars-- See Also:
-
getToolBar
Gets the first tool bar for this View- Returns:
- The first
JToolBarfor this View - See Also:
-
setToolBar
Sets the only tool bar for this View.This is a bound property.
- Parameters:
toolBar- TheJToolBarfor this view. Ifnullresets the tool bar.- See Also:
-
getStatusBar
Returns the Status bar for this View.- Returns:
- The status bar
JComponentfor this View
-
setStatusBar
Sets the status bar for this View. The status bar is a genericJComponent.- Parameters:
statusBar- The status barJComponentfor this View
-