I have a javafx code like this
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/view/Login.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Welcom to MSS Login");
stage.setResizable(false);
stage.show();
}
Here I already setResizable(false); but I still can resize the window when run app. How to set a window not resizeable?
Thanks
I came across this problem today, trying to create some windows for my database management system and I clearly wanted fixed window size, non resizable, but unfortunately this is not fully supported by Ubuntu 16.04 LTS, which seems to have a different approach to how it performs with window size handlers.
However, I found the fix after none of stageStyle("TRANSPARENT"), setResizable(false) did not work.
The second one would normally work on Windows.
The fix for Ubuntu:
primaryStage.setMaxHeight(yourH);
primaryStage.setMinHeight(yourH);
primaryStage.setMaxWidth(yourW);
primaryStage.setMinWidth(yourW);
Related
I have a main stage with these properties. It is meant to be a secure "lockdown stage"
public static Stage getSecureStage(Window window) throws IOException {
Stage stage = new Stage();
//Take up the entire screen boundaries
Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
stage.setHeight(visualBounds.getHeight());
stage.setWidth(visualBounds.getWidth());
//Secure the stage
stage.setFullScreen(true);
stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
stage.setFullScreenExitHint(null);
stage.initModality(Modality.APPLICATION_MODAL);
stage.initStyle(StageStyle.UNDECORATED);
stage.setScene(getScene(window));
return stage;
}
With this lockdown stage, I want to be able to have popup windows within the stage stay on top
As you can see, the stage initializes on top of the lockdown stage. However, if I am to click off of that popup and back onto the main lockdown stage, the lockdown stage takes priority and puts itself over the popup. It does not minimize it, but just goes on top.
I have given the popup the properties
popup.setAlwaysOnTop(true);
popup.initOwner(lockdownStage);
however, that does not seem to do the trick. I had not previously had this issue running on Linux, with the same code. Please let me know if you need anymore information
Solved this by getting rid of the
stage.setFullScreen(true);
stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
stage.setFullScreenExitHint(null);
and setting it instead to
stage.setMaximized(true);
With the previous fullscreen setup, you could also use the stage.initModality(Modality.APPLICATION_MODAL); on the popup window. In my case, I wanted to be able to interact with both windows not singling one out with the modality feature.
I want to be able to play sound from mp3 files for which I saw posts recommending the usage of JavaFX. I implemented the MediaPlayer and initialized the JFXPanel and in eclipse, everything works lovely.
Yet when I export to a runnable jar, and try running the program, I get the following error message: java.lang.NoClassDefFoundError: javafx/scene/media/MediaException.
I presume this is from the exclusion of JavaFX in the newer JRE versions (which I came across during my search to a solution). My main question is how do I ship the jar with JavaFX? Do I have to include a jar, and if yes, where do I get it? Because eclipse doesn't seem to package JavaFX into my runnable if I'm not mistaken.
Here an example which, for me, already triggers this behavior:
// This would throw a java.lang.NoClassDefFoundError for the JFXPanel but is effectively the same problem
public class Test extends Application
{
public static void main(String[] Args)
{
launch(Args);
}
#Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
StackPane root = new StackPane();
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
}
Thank you for your help!
JavaFx was removed into JDK> = 11 and now is a separate project opensurse [openjfx] (https://openjfx.io/).
And now it is to be made more difficult to create a version of the application javafx runnable everywhere, but it is a continuous evolution and I think that this is good documentation [doc-image-live] (https://openjfx.io/openjfx-docs/#modular).
I had a problem simile when I used for the developing the JDK 1.8 but in my version java system is openjdk11, I think this is the same case.
Your example is wrong because not is a JavaFX application.
The JavaFX application must extend the javafx.application.Application and in the main call the method launch, this method will call the method start inherited from Application.
This is a simple example of the Oracle
public class HelloWorld extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
}
ps: When you speak the javafx, you must add the java version because we don't know your java version
An alternative path, if you prefer to not use JavaFX, would be to make use of the libraries that originated from JavaZOOM for the task of reading the mp3 files. I am seeing many offerings on github that have been derived from this source, for example, https://github.com/goxr3plus/java-sound-libraries But I have not made use of this particular library myself.
My preference has been to combine JavaFX for GUI with javax.audio.sampled, and a library I built that relies on java.sound.sampled.SourceDataLine for output. But I never bothered to implement reading mp3s. I tend to take the ogg/vorbis route when using compressed audio resources.
My first intention was to set TextInputDialog icon. But I started from setting stage icon. I saw couple SO questions with marvelous answers containing usually 2 lines of code.
First I tried to put this icon to /resources/icons but exception "Invalid URL or resource not found" appeared. To be sure I don't make any mistake writing file path I moved this icon to /source/sample directory. I use code (I will post whole code):
public void start(Stage stage) throws Exception {
FXMLLoader loaderModyfikacjaKonfiguracji = new FXMLLoader(getClass().getResource("FXMLModyfikacjaKonfiguracji.fxml"));
Parent root = loaderModyfikacjaKonfiguracji.load();
stage.setTitle("Modyfikacja konfiguracji");
Image image = new Image("file:icon.png");
//stage.getIcons().removeAll();
stage.getIcons().add(image);
ControllerModyfikacjaKonfiguracji controllerModyfikacjaKonfiguracji = loaderModyfikacjaKonfiguracji.getController();
stage.setScene(new Scene(root, 510, 700));
stage.show();
}
Everywhere it looks so simple to set icon. I also tried .jpg. not using file: throws exception, using file: compiles but I see no effect of changed icon. What am I doing wrong or where is the problem?
I've successfully used this to set an icon before
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("AppIcon.png")));
In my case, the application fxml file and AppIcon.png are in the same directory.
If you dont want to go that route, i would suggest trying
Image image = new Image("file:./icon.png");
But that's a guess.
I recently asked a similar question about this for OSX and found a solution using the com.sun.glass package. However, this solution does not seem to work on X11-based desktop environments.
The issue:
I am trying to write a borderless window overlay that can be placed above ALL other desktop components, including the dock and menubar of any given Linux desktop environment which uses x11. Currently, when I use AlwaysOnTop(true) with my JavaFX window, the window is placed above all other windows but is NOT placed above the window managers UI (taskbar) due to it having a higher window level. The screenshot below shows what happens when using AlwaysOnTop: the entirety of the vertical white window should be placed above the taskbar but is instead forced below it. See screenshot:
There is a solution for this issue with Qt through using the x11bypasswindowmanager window flag, so I figured it must be possible through Java!
The only current solution I have is to use wmctrl directly through the commandline using a subprocess. This is not really suitable, as a lot of linux systems to not come with wmctrl installed.
Below is the code snippet I am using to generate the window in the above screenshot:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
StackPane root = new StackPane();
primaryStage.setScene(new Scene(root, 200, 3000));
primaryStage.setAlwaysOnTop(true);
primaryStage.initStyle(StageStyle.UNDECORATED);
primaryStage.setX(800);
primaryStage.setY(0);
primaryStage.show();
}
}
Im making an kinda information like application for a city and I would like to use either multiple or a scene that gets updated. Is this possible and if so any tips?
#Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Informative Program");
primaryStage.setScene(new Scene(root, 1000, 600));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
The beauty of JavaFX is that you can add listeners to your application to dynamically change any part of your application, including the entire scene.
By using your example you can do
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
scene.setRoot(root);`
root = FXMLLoader.load(getClass().getResource("sample2.fxml"));
scene.setRoot(root2);
Essentially you just need to load a need root and then set it, and you should be good to go.
I use this personally for an Application I've been writing where the users log in first, and then it changes the root node to the next screen after login.
You could change your root at any point, or you could add/remove elements from the root, at any point, as well.
JavaFX is great in how Dynamic/Flexible it is as a language/Framework