MCPcopy Create free account
hub / github.com/dorkbox/SystemTray / doJavaFxStuff

Method doJavaFxStuff

test-javaFx/dorkbox/TestTrayJavaFX.java:102–251  ·  view source on GitHub ↗
(final Stage stage)

Source from the content-addressed store, hash-verified

100 }
101
102 public
103 void doJavaFxStuff(final Stage stage) {
104 stage.setTitle("Hello World JavaFx!");
105 Button btn = new Button();
106 btn.setText("Say 'Hello World JavaFx'");
107 btn.setOnAction(event->System.out.println("Hello World JavaFx!"));
108
109 StackPane root = new StackPane();
110 root.getChildren().add(btn);
111 stage.setScene(new Scene(root, 300, 250));
112 stage.show();
113
114 // required, so the rendering back-end knows that we are using JavaFX
115 RenderProvider.set(new JavaFxProvider());
116
117 SystemTray.DEBUG = true; // for test apps, we always want to run in debug mode
118
119 // for test apps, make sure the cache is always reset. These are the ones used, and you should never do this in production.
120 CacheUtil.clear("SysTrayExample");
121
122 // SwingUtil.setLookAndFeel(null); // set Native L&F (this is the System L&F instead of CrossPlatform L&F)
123 // SystemTray.SWING_UI = new CustomSwingUI();
124
125 this.systemTray = SystemTray.get("SysTrayExample");
126 if (systemTray == null) {
127 throw new RuntimeException("Unable to load SystemTray!");
128 }
129
130 // SWT/JavaFX "shutdown hooks" have changed. Since it's no longer available with JPMS, it is no longer supported.
131 // Developers must add the shutdown hooks themselves.
132
133 systemTray.setTooltip("Mail Checker");
134 systemTray.setImage(LT_GRAY_TRAIN);
135 systemTray.setStatus("No Mail");
136
137 callbackGray = e->{
138 final MenuItem entry = (MenuItem) e.getSource();
139 systemTray.setStatus(null);
140 systemTray.setImage(BLACK_TRAIN);
141
142 entry.setCallback(null);
143// systemTray.setStatus("Mail Empty");
144 systemTray.getMenu().remove(entry);
145 System.err.println("POW");
146 };
147
148
149 Menu mainMenu = systemTray.getMenu();
150
151 MenuItem greenEntry = new MenuItem("Green Mail", e->{
152 final MenuItem entry = (MenuItem) e.getSource();
153 systemTray.setStatus("Some Mail!");
154 systemTray.setImage(GREEN_TRAIN);
155
156 entry.setCallback(callbackGray);
157 entry.setImage(BLACK_MAIL);
158 entry.setText("Delete Mail");
159 entry.setTooltip(null); // remove the tooltip

Callers 1

startMethod · 0.80

Calls 15

getMethod · 0.95
setCallbackMethod · 0.95
setImageMethod · 0.95
setTextMethod · 0.95
setTooltipMethod · 0.95
setShortcutMethod · 0.95
addMethod · 0.95
setShortcutMethod · 0.95
removeMethod · 0.95
setEnabledMethod · 0.95
showMethod · 0.80
getMenuMethod · 0.80

Tested by

no test coverage detected