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 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 to `BorderLayout.NORTH` of the rootPane's contentPane
- `component` - added to `BorderLayout.CENTER` of the rootPane's contentPane
- `statusBar` - added to `BorderLayout.SOUTH` of 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

Modifier and Type
Method
Description
`final Application`
`getApplication()`
Returns the `Application` that's responsible for showing/hiding this View.
`JComponent`
`getComponent()`
Returns the main `JComponent` for this View.
`final ApplicationContext`
`getContext()`
Gets the `ApplicationContext` for the `Application` that's responsible for showing/hiding this View.
`JMenuBar`
`getMenuBar()`
Returns the main `JMenuBar` for this View.
`ResourceMap`
`getResourceMap()`
Gets `ResourceMap` for this View.
`JRootPane`
`getRootPane()`
Gets the `JRootPane` for this View.
`JComponent`
`getStatusBar()`
Returns the Status bar for this View.
`final JToolBar`
`getToolBar()`
Gets the first tool bar for this View
`List<JToolBar>`
`getToolBars()`
Returns the list of tool bars for this View
`void`
`setComponent(JComponent component)`
Sets the single main Component for this View.
`void`
`setMenuBar(JMenuBar menuBar)`
Sets the menu bar for this View.
`void`
`setStatusBar(JComponent statusBar)`
Sets the status bar for this View.
`final void`
`setToolBar(JToolBar toolBar)`
Sets the only tool bar for this View.
`void`
`setToolBars(List<JToolBar> toolBars)`
Sets the tool bars for this View

### Methods inherited from class org.jdesktop.application.AbstractBean

`addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### 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 Details

### getApplication

public final Application getApplication()
Returns the `Application` that'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()
Gets the `ApplicationContext` for the `Application` that's responsible for showing/hiding this View. This method is just shorthand for `getApplication().getContext()`.

Returns:
  the Application that owns this View
See Also:
  - `getApplication()`
  - `Application.show(View)`
  - `Application.hide(View)`

### getResourceMap

public ResourceMap getResourceMap()
Gets `ResourceMap` for this View. This method invokes `getContext().getResourceMap(getClass(), View.class)`. The result is cached.

Returns:
  The `ResourceMap` for this View
See Also:
  - `getContext()`

### getRootPane

public JRootPane getRootPane()
Gets the `JRootPane` for this View. All of the components for this View must be added to its rootPane. Most applications will do so by setting the View's `component`, `menuBar`, `toolBar`, and `statusBar` properties.

Returns:
  The `rootPane` for this View
See Also:
  - `setComponent(javax.swing.JComponent)`
  - `setMenuBar(javax.swing.JMenuBar)`
  - `setToolBar(javax.swing.JToolBar)`
  - `setStatusBar(javax.swing.JComponent)`

### getComponent

public JComponent getComponent()
Returns the main `JComponent` for this View.

Returns:
  The `component` for this View
See Also:
  - `setComponent(javax.swing.JComponent)`

### setComponent

public void setComponent(JComponent component)
Sets the single main Component for this View. It's added to the `BorderLayout.CENTER` of 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` - The `component` for this View
See Also:
  - `getComponent()`

### getMenuBar

public JMenuBar getMenuBar()
Returns the main `JMenuBar` for this View.

Returns:
  The `menuBar` for this View
See Also:
  - `setMenuBar(javax.swing.JMenuBar)`

### setMenuBar

public void setMenuBar(JMenuBar menuBar)
Sets the menu bar for this View.

This is a bound property. The default value is null.

Parameters:
  `menuBar` - The `menuBar` for this View
See Also:
  - `getMenuBar()`

### getToolBars

public List<JToolBar> getToolBars()
Returns the list of tool bars for this View

Returns:
  The list of tool bars

### setToolBars

public void setToolBars(List<JToolBar> toolBars)
Sets the tool bars for this View

This is a bound property. The default value is an empty list.

Parameters:
  `toolBars` -
See Also:
  - `setToolBar(JToolBar)`
  - `getToolBars()`

### getToolBar

public final JToolBar getToolBar()
Gets the first tool bar for this View

Returns:
  The first `JToolBar` for this View
See Also:
  - `setToolBars(java.util.List<javax.swing.JToolBar>)`
  - `getToolBars()`
  - `setToolBar(javax.swing.JToolBar)`

### setToolBar

public final void setToolBar(JToolBar toolBar)
Sets the only tool bar for this View.

This is a bound property.

Parameters:
  `toolBar` - The `JToolBar` for this view. If `null` resets the tool bar.
See Also:
  - `getToolBar()`
  - `setToolBars(List)`
  - `getToolBars()`

### getStatusBar

public JComponent getStatusBar()
Returns the Status bar for this View.

Returns:
  The status bar `JComponent` for this View

### setStatusBar

public void setStatusBar(JComponent statusBar)
Sets the status bar for this View. The status bar is a generic `JComponent`.

Parameters:
  `statusBar` - The status bar `JComponent` for this View