-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFXUtil.java
More file actions
41 lines (35 loc) · 1.32 KB
/
FXUtil.java
File metadata and controls
41 lines (35 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package me.david.sploty4.util;
import javafx.application.Platform;
import javafx.scene.control.Labeled;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import me.david.sploty4.Sploty;
import java.io.IOException;
import java.io.InputStream;
public final class FXUtil {
public static void setImage(Labeled label, String image){
if (Platform.isFxApplicationThread()) loadImage(label, image);
else Platform.runLater(() -> loadImage(label, image));
}
private static void loadImage(Labeled label, String image) {
try {
InputStream is = FXUtil.class.getResourceAsStream(image);
if (is != null && is.available() <= 20)
Sploty.getLogger().warn("InputStream seam to be invalid: " + image + " " + is.toString());
label.setGraphic(new ImageView(new Image(is)));
is.close();
} catch (IOException e) {
Sploty.getLogger().exception(e, "Failed loading Image in Jar");
}
}
public static Image getImage(String loc){
InputStream is = FXUtil.class.getResourceAsStream(loc);
Image image = new Image(is);
try {
is.close();
} catch (IOException e) {
Sploty.getLogger().exception(e, "Failed closing Image Stream");
}
return image;
}
}