@ -6,7 +6,7 @@ In this guide, we'll show you how to work with windows using Compose for Desktop
## Windows creation
The main class for creating windows is AppWindow. The easiest way to create and launch a new window is to use an instance of the AppWindow class and call its method show(). You can see an example below:
The main class for creating windows is AppWindow. The easiest way to create and launch a new window is to use an instance of the AppWindow class and call its method `show()`. You can see an example below:
```kotlin
import androidx.compose.desktop.AppWindow
@ -18,15 +18,16 @@ fun main() {
}
```
There are two types of windows - modal and active. Below are functions for creating each type of window:
There are two types of windows - modal and regular. Below are functions for creating each type of window:
1. Window - active window type.
1. Window - regular window type.
2. Dialog - modal window type. Such a window locks its parent window until the user completes working with it and closes the modal window.
You can see an example for both types of windows below.
```kotlin
import androidx.compose.desktop.Window
import androidx.compose.foundation.Text
import androidx.compose.material.Button
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@ -36,7 +37,9 @@ fun main() {
Window {
val dialogState = remember { mutableStateOf(false) }
Button(onClick = { dialogState.value = true })
Button(onClick = { dialogState.value = true }) {
Text(text = "Open dialog")
}
if (dialogState.value) {
Dialog(
@ -51,7 +54,7 @@ fun main() {
## Window attributes
Each window has 9 parameters listed below:
Each window has 9 parameters listed below, all of them could be omitted and have default values:
1. title - window title
2. size - initial window size
@ -66,33 +69,94 @@ Each window has 9 parameters listed below:
An example of using window parameters at the creation step:
The AppManager class is used to customize the behavior of the entire application. Its main features:
The AppManager singleton is used to customize the behavior of the entire application. Its main features:
1. Description of common application events
```kotlin
AppManager.onEvent(
onAppStart = { println("OnAppStart") },
onAppExit = { println("OnAppExit") }
AppManager.setEvents(
onAppStart = { println("onAppStart") }, // invoked before the first window is created
onAppExit = { println("onAppExit") } // invoked after all windows are closed
)
```
2. Customization of common application context menu
```kotlin
AppManager.menu(
AppManager.setMenu(
getCommonAppMenuBar() // custom function that returns MenuBar
)
```
3. Access to the application windows list
```kotlin
val windows = AppManager.getWindows()
val windows = AppManager.windows
```
4. Getting the current focused window
```kotlin
val current = AppManager.getCurrentFocusedWindow()
val current = AppManager.focusedWindow
```
5. Application exit
```kotlin
AppManager.exit() // closes all windows
```
## Access to javax.swing components
## Access to Swing components
Compose for Desktop uses Swing components as the window system. For more detailed customization, you can access the JFrame (Swing window representation):
Compose for Desktop is tightly integrated with Swing on the level of top level windows. For more detailed customization, you can access the JFrame (Swing window representation):