diff --git a/tutorials/Tray_Notifications_MenuBar/TrayNotifierMenuBar.md b/tutorials/Tray_Notifications_MenuBar/TrayNotifierMenuBar.md index 03b15dd5e5..394b1aacc7 100755 --- a/tutorials/Tray_Notifications_MenuBar/TrayNotifierMenuBar.md +++ b/tutorials/Tray_Notifications_MenuBar/TrayNotifierMenuBar.md @@ -31,10 +31,12 @@ import java.awt.image.BufferedImage fun main() { val count = mutableStateOf(0) - Window { + Window( + icon = getMyAppIcon() + ) { onActive { val tray = Tray().apply { - icon(getMyAppIcon()) + icon(getTrayIcon()) menu( MenuItem( name = "Increment value", @@ -72,6 +74,20 @@ fun main() { } fun getMyAppIcon() : BufferedImage { + val size = 256 + val image = BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB) + val graphics = image.createGraphics() + graphics.setColor(Color.green) + graphics.fillOval(size / 4, 0, size / 2, size) + graphics.setColor(Color.blue) + graphics.fillOval(0, size / 4, size, size / 2) + graphics.setColor(Color.red) + graphics.fillOval(size / 4, size / 4, size / 2, size / 2) + graphics.dispose() + return image +} + +fun getTrayIcon() : BufferedImage { val size = 256 val image = BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB) val graphics = image.createGraphics() @@ -98,11 +114,16 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.Text import androidx.compose.material.Button import androidx.compose.ui.window.Notifier +import java.awt.Color +import java.awt.Graphics2D +import java.awt.image.BufferedImage fun main() { val message = "Some message!" val notifier = Notifier() - Window { + Window( + icon = getMyAppIcon() + ) { Column { Button(onClick = { notifier.notify("Notification.", message) }) { Text(text = "Notify") @@ -116,6 +137,20 @@ fun main() { } } } + +fun getMyAppIcon() : BufferedImage { + val size = 256 + val image = BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB) + val graphics = image.createGraphics() + graphics.setColor(Color.green) + graphics.fillOval(size / 4, 0, size / 2, size) + graphics.setColor(Color.blue) + graphics.fillOval(0, size / 4, size, size / 2) + graphics.setColor(Color.red) + graphics.fillOval(size / 4, size / 4, size / 2, size / 2) + graphics.dispose() + return image +} ``` ![Notifier](notifier.gif) diff --git a/tutorials/Tray_Notifications_MenuBar/notifier.gif b/tutorials/Tray_Notifications_MenuBar/notifier.gif index 1013f5d96d..9ab6638f77 100644 Binary files a/tutorials/Tray_Notifications_MenuBar/notifier.gif and b/tutorials/Tray_Notifications_MenuBar/notifier.gif differ diff --git a/tutorials/Tray_Notifications_MenuBar/tray.gif b/tutorials/Tray_Notifications_MenuBar/tray.gif index b85ab5a284..4f42bcb2a1 100644 Binary files a/tutorials/Tray_Notifications_MenuBar/tray.gif and b/tutorials/Tray_Notifications_MenuBar/tray.gif differ