JavaFX disabled maximize button reappears after closing an Alert - java

I'm creating a JavaFX application (on OSX) which consists of a stage.
It should neither be allowed to resize it manually nor to enter full screen via the maximize button. This is currently achieved by stage.setResizable(false) which works fine.
The problem occurs when adding an Alert: After closing the Alert, the maximize button becomes targetable again, making it possible to enter full screen.
Here's a simple example of code:
// imports
public class MyApplication extends Application {
public static void main(String[] args) { launch(args); }
#Override
public void start(Stage primaryStage) {
primaryStage.setScene(new Scene(new StackPane()));
primaryStage.setResizable(false);
primaryStage.setOnCloseRequest(event -> {
Alert alert = new Alert(AlertType.CONFIRMATION, "Close?");
if (alert.showAndWait().get().equals(ButtonType.CANCEL)) {
event.consume();
}});
primaryStage.show();
}
}
Does anyone know why this is happening?

Related

Output formate changed java

I am new in Java. I am trying to learn to make some view in javafx. Here, I am trying to write some simple code to create button in a scene. Button is created successfully but the issue is not showing output properly. And I don't know how to search this type of issue but I look javafx documents. But, didn't find any solution.
Here is my code.
public class PlayingCard extends Application {
#Override
public void start(Stage primaryStage) {
System.out.println("hello world");
primaryStage.setTitle("Button Title");
Button btn = new Button("Click HERE");
StackPane layout = new StackPane();
layout.getChildren().add(btn);
Scene scena = new Scene(layout, 600, 300);
primaryStage.setScene(scena);
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
I know there is nothing wrong in the code. I missed some setting. Here I am posting output screenshot.
And addition, when I add imageview with some image the same thing like output was not shown.

JavaFx Not able to pass a value from a class to configure setScene

I am a Newbie trying to learn java and I am a complete beginner at java Fx so please forgive the noob question but I am trying to structure my code more cleanly by having all my buttons in a class but I know that I have to have the variable 'button' in a StackPane but when I do it it tells me that java can't find the variable. if someone can help me then that would be greatly appreciated. (also when the button is not in another class the code worked)
//this class is for drawing the buttons
public void Buttons() {
Button button = new Button("My Button");
}
public static void main(String[] args) { launch(args); }
#Override
public void start(Stage primaryStage) {
//this sets the Title for the window
primaryStage.setTitle("Calcultor");
//this calls the class that draws the buttons on screen
Buttons();
StackPane root = new StackPane();
root.getChildren().add(button);
//this cerates a stage and sets the window size
primaryStage.setScene(new Scene(root, 300, 400));
//this refreshes the window
primaryStage.show();
}
}

stage.setIconify(true) doesn't work with undecorated stage

I have an undecorated FXML stage. I created a button to minimize window and created an event for it in Controller class in initialize method.
minimizeBtn.setOnAction(e -> {
Stage stage = (Stage)((Button)e.getSource()).getScene().getWindow();
stage.setIconified(true);
System.out.println(stage.isIconified());
});
Problem:
isIconified() returns true, while nothing happens to window visually.
If I switch from UNDECORATED to default my custom button perfectly works.
Same problem for me on both MacOS High Sierra and Mojave, with jdk 11.0.2 and JavaFX 12.0.1
There's the example code to reproduce the issue.
Note that without setting the UNDECORATED style to the stage the problem doesnt' happen.
On Windows the behaviour is correct no matter what the stage style is.
public class DemoApplication extends Application {
#Override
public void start(Stage primaryStage) {
Button minimize = new Button("MINIMIZE");
minimize.setOnAction(event -> primaryStage.setIconified(true));
primaryStage.initStyle(StageStyle.UNDECORATED);
Scene scene = new Scene(new StackPane(minimize));
primaryStage.setTitle("JavaFX App");
primaryStage.setWidth(960);
primaryStage.setHeight(600);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}

JavaFx, pane not displaying the browser

I have a JavaFX interface generated by SceneBuilder...so I have my view components in sample.fxml.
When I start the application it looks like this : http://i.imgur.com/3tj0tN9.png
In that blue pane I want to add the browser ( with JxBrowser library), so I did this:
public void loadMap(ActionEvent actionEvent) {
initComponents(); //setting my buttons visibility
Browser browser = new Browser();
BrowserView browserView = new BrowserView(browser);
gamePane.getChildren().add(browserView);
browser.loadURL("http://www.google.com");
gamePane.getChildren().add(new Button("random"));
}
This is my main:
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Google Maps ");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
That button was added, but my browser won't appear..What can I do?I used this in Swing and it worked,but here seems not.
The browser is loaded(because I get the specific messages in console) but isn't displayed.

Executable Jar limited to one window with JavaFX

I am building a JavaFX application through E(fx)clipse and Java Scene Builder.
The basic functionality is a login window. Once logged in, new window opens and the login window disapears. Right now it's just at the prototype stage.
When running out of ecplise, the functionality I want is all there. Login window shows up on start (code looking as such)
#Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("view/login.fxml"), ResourceBundle.getBundle("ca.sportstats.resources.labels"));
primaryStage.setTitle("SportStats Live Update Tool : Login");
primaryStage.setScene(new Scene(root, 450, 300));
primaryStage.show();
} catch (IOException e) {
//Change this to open a small popup window.
System.out.println("Could not deploy");
}
}
public static void main(String[] args) {
launch(args);
}
There is one button on this window that simply opens another (the login logic will come later and not an issue here).
btnLogin.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
//TODO: Login logic.
//On success allow to open the tool (aka main window);
Parent root;
try {
root = FXMLLoader.load(getClass().getResource("../view/selector.fxml"), resources);
Stage stage = new Stage();
stage.setTitle("Selector");
stage.setScene(new Scene(root, 450, 450));
stage.show();
//hide this current window
((Node)(event.getSource())).getScene().getWindow().hide();
} catch (IOException e) {
e.printStackTrace();
}
}
});
This works no problem in Ecplise. BUT! When I build this (in the fashion described on the e(fx)clipse tutorials I get an executable jar, but only get the login window. When I click my button the 2nd window doesn't show up.
The problem I think is that in jars you can't do relative paths. Inside Eclipse you are running on the filesystem where this is not a problem

Categories