# Screen

Import: `import com.install4j.api.screens.Screen;`

```java
interface Screen extends VisualContainerBean
```

The base interface for all screens. Do not implement this interface directly, only the derived interfaces are
functional. It is recommended that you choose one of the derived abstract classes as
a superclass. The life-cycle of screens is controlled by the framework.

## Inherited from

- [VisualContainerBean](../beans/VisualContainerBean.md) — 3 methods

## Methods

| Signature | Returns | Description |
|---|---|---|
| [`createComponent()`](#createcomponent) | `JComponent` | Return the visual component that is displayed for the screen. |
| [`getTitle()`](#gettitle) | `String` | Returns the title of this custom screen which is displayed at the top of the installer wizard. |
| [`getSubTitle()`](#getsubtitle) | `String` | Returns the subtitle of this custom screen which is displayed at the top of the installer wizard just below the title of the screen. |
| [`isNextVisible()`](#isnextvisible) | `boolean` | Returns whether the "Next" button is visible or not for this screen. |
| [`isPreviousVisible()`](#ispreviousvisible) | `boolean` | Returns whether the "Back" button is visible or not for this screen. |
| [`isCancelVisible()`](#iscancelvisible) | `boolean` | Returns whether the "Cancel" button is visible or not for this screen. |
| [`willActivate()`](#willactivate) | `void` | Called by the framework just before the screen is activated. |
| [`activated()`](#activated) | `void` | Called by the framework just after the screen has been activated. |
| [`deactivated()`](#deactivated) | `void` | Called by the framework just after the screen has been deactivated. |
| [`next()`](#next) | `boolean` | Called when the user clicks the "Next" button for this screen. |
| [`previous()`](#previous) | `boolean` | Called when the user clicks the "Back" button for this screen. |
| [`cancel()`](#cancel) | `boolean` | Called when the user clicks the "Cancel" button for this screen. |
| [`isHiddenForNext()`](#ishiddenfornext) | `boolean` | Returns whether this screen should be hidden when the user traverses screens in the forward direction. |
| [`isHiddenForPrevious()`](#ishiddenforprevious) | `boolean` | Returns whether this screen should be hidden when the user traverses screens in the backward direction. |
| [`isHidden()`](#ishidden) | `boolean` | Returns whether this screen should be hidden. |
| [`handleUnattended()`](#handleunattended) | `boolean` | Handle the unattended mode. |
| [`handleConsole(Console)`](#handleconsole-console) | `boolean` | Handle the console mode. |
| [`getProgressInterface(ProgressInterface)`](#getprogressinterface-progressinterface) | `ProgressInterface` | Replace the default progress interface for actions with a custom progress interface. |
| [`isCreateLazily()`](#iscreatelazily) | `boolean` | This method is called by the framework to determine if the screen should only be created when it is shown. |
| [`setWidgetStyleHandler(WidgetStyleHandler)`](#setwidgetstylehandler-widgetstylehandler) | `void` | This method is called by the framework to set the `WidgetStyleHandler` just after the screen has been constructed. |

### createComponent()

```java
JComponent createComponent()
```

Return the visual component that is displayed for the screen. This method is only called once, so the
result does not have to be cached.

In unattended mode, this method is never called. In console mode, this method is called, but the
returned component is not used.


**Returns:** the component

### getTitle()

```java
String getTitle()
```

Returns the title of this custom screen which is displayed at the top of the
installer wizard.

In console or unattended mode, this method is never called.


**Returns:** the title.

### getSubTitle()

```java
String getSubTitle()
```

Returns the subtitle of this custom screen which is displayed at the top of the
installer wizard just below the title of the screen.

In unattended mode, this method is never called.
In console mode, the result of this method will be displayed for each screen.


**Returns:** the subtitle.

### isNextVisible()

```java
boolean isNextVisible()
```

Returns whether the "Next" button is visible or not for this screen. If you just want to disable the
button initially, please override `activated` and invoke `setNextButtonEnabled` in the
`WizardContext` that is available from the `Context` in GUI mode.

In console or unattended mode, this method is never called.


**Returns:** `true` or `false`. Default is `true`.

**See also:**

- [WizardContext](../context/WizardContext.md)

### isPreviousVisible()

```java
boolean isPreviousVisible()
```

Returns whether the "Back" button is visible or not for this screen. If you just want to disable the
button initially, please override `activated` and invoke `setBackButtonEnabled` in the
`WizardContext` that is available from the `Context` in GUI mode.

In console or unattended mode, this method is never called.


**Returns:** `true` or `false`. Default is `true`.

**See also:**

- [WizardContext](../context/WizardContext.md)

### isCancelVisible()

```java
boolean isCancelVisible()
```

Returns whether the "Cancel" button is visible or not for this screen. If you just want to disable the
button initially, please override `activated` and invoke `setCancelButtonEnabled` in the
`WizardContext` that is available from the `Context` in GUI mode.

In console or unattended mode, this method is never called.


**Returns:** `true` or `false`. Default is `true`.

**See also:**

- [WizardContext](../context/WizardContext.md)

### willActivate()

```java
void willActivate()
```

Called by the framework just before the screen is activated. Override this method to perform any
special initialization.

In console or unattended mode, this method is never called.

### activated()

```java
void activated()
```

Called by the framework just after the screen has been activated. Override this method to perform any
special initialization.

In console or unattended mode, this method is never called.

### deactivated()

```java
void deactivated()
```

Called by the framework just after the screen has been deactivated. Override this method to perform any
special cleanup.

In console or unattended mode, this method is never called.

### next()

```java
boolean next()
```

Called when the user clicks the "Next" button for this screen. You can veto the change to the next
screen if you return `false`.

In console or unattended mode, this method is never called.


**Returns:** whether the screen change is accepted or not.

### previous()

```java
boolean previous()
```

Called when the user clicks the "Back" button for this screen. You can veto the change to the previous
screen if you return `false`.

In console or unattended mode, this method is never called.


**Returns:** whether the screen change is accepted or not.

### cancel()

```java
boolean cancel()
```

Called when the user clicks the "Cancel" button for this screen. You can veto the cancel action
if you return `false`.


**Returns:** whether the cancellation is accepted or not.

In console or unattended mode, this method is never called.

### isHiddenForNext()

```java
boolean isHiddenForNext()
```

Returns whether this screen should be hidden when the user traverses screens
in the forward direction.

This method is also called in console or unattended mode.


**Returns:** `true` or `false`.

### isHiddenForPrevious()

```java
boolean isHiddenForPrevious()
```

Returns whether this screen should be hidden when the user traverses screens
in the backward direction.

This method is also called in console or unattended mode.


**Returns:** `true` or `false`.

### isHidden()

```java
boolean isHidden()
```

Returns whether this screen should be hidden. If this method returns `true`,
it overrides the results of `isHiddenForNext` and `isHiddenForPrevious`.

This method is also called in console or unattended mode.


**Returns:** `true` or `false`.

**See also:**

- [Screen.isHiddenForNext](Screen.md#ishiddenfornext)
- [Screen.isHiddenForPrevious](Screen.md#ishiddenforprevious)

### handleUnattended()

```java
boolean handleUnattended()
```

Handle the unattended mode. This method is called when the screen is traversed in unattended mode.
There is no way to interact with the user. This method might be necessary to
mirror some behavior from the GUI mode, such as setting installer variables or configuring actions.


**Returns:** whether the installer or uninstaller can proceed with the next screen or whether the process should be canceled.

### handleConsole(Console)

```java
boolean handleConsole(Console console) throws UserCanceledException
```

Handle the console mode. This method is called when the screen is entered in console mode.
You can use the `Console` object to interact with the user and replicate the GUI functionality
on the terminal.

If this screen has a form panel (i.e. `hasFormPanel()` returns `true`), you should call
`FormEnvironment.handleConsole` in this method to handle console mode for the contained
form components.


**Parameters:**

- `console` — the `Console` object

**Returns:** whether the installer or uninstaller can proceed with the next screen or whether the process should be canceled.

**Throws:**

- `UserCanceledException` — if the user cancels a question or notice. These exceptions are thrown by methods in the `Console` object.

**See also:**

- [FormEnvironment.handleConsole](../formcomponents/FormEnvironment.md#handleconsole-console)

### getProgressInterface(ProgressInterface)

```java
ProgressInterface getProgressInterface(ProgressInterface defaultProgressInterface)
```

Replace the default progress interface for actions with a custom progress interface.
When associated actions are run for a screen, a default progress interface is passed to them. If your screen has the possibility to
show progress information, you can return a different progress interface here. Typically you would only implement
methods regarding status and detail messages as well as methods that apply to a progress bar, other methods can be
delegated to the default progress interface. This is the strategy employed by the "Installation screen" and the
customizable "Progress screens".


**Parameters:**

- `defaultProgressInterface` — the default progress interface

**Returns:** the replaced progress interface

### isCreateLazily()

```java
boolean isCreateLazily()
```

This method is called by the framework to determine if the screen should only be created when it is shown.
By default, all screens provided by install4j are _not_ created lazily. If you depend on custom code that
has to be installed before [`Screen.createComponent`](Screen.md#createcomponent) can be called, then you should return `true` in
this method.

If you have many screens that are created lazily and want to initialize them all at once, maybe after the
"Install files" action, you can call [`Context.initializeLazilyCreatedScreens`](../context/Context.md#initializelazilycreatedscreens).


**Returns:** `true` or `false`.

### setWidgetStyleHandler(WidgetStyleHandler)

```java
void setWidgetStyleHandler(WidgetStyleHandler widgetStyleHandler)
```

This method is called by the framework to set the  `WidgetStyleHandler` just after the
screen has been constructed.


**Parameters:**

- `widgetStyleHandler` — the widget style handler.

