JavaFX - Open window in iconified/minimized mode? - javafx

Is it possible to open a window in minimized mode using JavaFX?
Currently this code :
stage.setScene(scene);
stage.setMinHeight(currentWindowHeight);
stage.show();
opens window in the centre of the screen. Adding stage.setIconified(true) results in ugly flashed view of stage appearing for a millisecond and minimized. Can this behavior be optimized so the stage will open in minimized mode without flashing on screen? Thanks

Try this:
stage.setScene(scene);
stage.setMaxHeight(0);
stage.setMaxWidth(0);
stage.setOpacity(0);
stage.setIconified(true);
For the second half of your question,I would go here: Listener for a Stage minimizing, maximizing, etc
Before I setIconified I would save the original window's settings in an object. Maybe bounds object(just guessing here). I would then listen for maximizing and restore the original settings. On minimizing, I would re-Iconify. <- This is just me thowing ideas out. Stackover recomends you start a new question if your original question has been answered and you have new problems.

Related

Switching To Primary Scene When Secondary Scene Is Closed

I am using JavaFX 11 and a newbie.
I have a single stage with two scenes: a primary scene that shows on start and a secondary scene that is switched to and shown when I press a certain button on the main scene. On the secondary scene, I want to be able to switch back to the main scene when I click the close X button on the top right of the window instead of having the entire application close.
I currently have a method for the cancel button that looks like this:
public void cancelButtonPushed(ActionEvent event) throws IOException {
Parent parent = FXMLLoader.load(getClass().getResource("ExampleMainScreen.fxml"));
Scene scene = new Scene(parent);
Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
window.setScene(scene);
window.show();
}
This method allows me to switch back to the main scene when the Cancel button is pushed. However, I am lost trying to find something that can be used any time the user clicks the close X on the secondary scene.
First, get the terminology right, my guess is that you have two Stages. Scenes can be displayed inside those.
Second, Scene Builder (and the FXML it produces) does not manage stages, it only constructs nodes (and event handling for those nodes) that are placed inside scenes. So, you won't find the hooks you need to integrate with the window close functions in SceneBuilder or FXML.
Third, when a user wants to close a window (a stage is a kind of window), then an event will be emitted, which you can action onCloseRequest.
Fourth, somehow you have already managed to create a second stage, probably by calling new Stage(). This will provide you with a reference to the stage which you can set your close request on:
Stage secondaryStage = new Stage();
Stage setScene(secondaryScene);
secondaryStage.setOnCloseRequest(e -> primaryStage.show());
This will show your primary stage (which I guess you hid earlier), when the secondary stage is being closed, but before it has actually closed.
Next, read up on the Application lifecycle, specifically see the section which references Platform.setImplicitExit(boolean implicitExit):
If this attribute is true, the JavaFX runtime will implicitly shutdown when the last window is closed; the JavaFX launcher will call the Application.stop() method and terminate the JavaFX application thread. If this attribute is false, the application will continue to run normally even after the last window is closed, until the application calls exit(). The default value is true.
Note, that, you probably don't need to explicitly set the implicit exit flag if you handle the stage switching as outlined previously, but I provide the info for you in case you need to understand it.
Finally, consider whether you really should be creating new stages for your application and this particular task or just replacing the content in a single stage (similar to how a web browser works).

Why does Qt3DWindow on rare instances not render a scene and instead projects other parts of the GUI onto the window?

This is a rare bug, but sometimes when I start my Qt app the qt3d window which hosts my scene is blank (without any of my models), except the window itself seems to be bugged because it will mirror other parts of the GUI if I shift between tabs. So instead of my scene appearing in the window it'll contain information and widgets from another tab that's located in the same area as the window on a different tab.
This doesn't occur very often, which makes the bug hard to replicate. Has anyone else seen this behavior before or maybe it's the way I'm setting up the Qt3DExtras::Qt3DWindow?
Qt3DExtras::Qt3DWindow* view = new Qt3DExtras::Qt3DWindow();
view->defaultFrameGraph()->setClearColor(QColor(0,0,0));
view->setRootEntity(CreateScene());
// embed 3D Window in Widget
QWidget* container = QWidget::createWindowContainer(view);
ui->verticalLayout_visualizer->addWidget(container);

javafx: How to get back to original application window without closing the new window?

Apologies for asking such a simple question but english is not my first language, so I cannot find the right word to describe my problem and cannot google up the the right question.
I have a javafx application and there is a button whereby if the user clicks it, it generates a new window (like a display box just to display more info to a user). The problem is when the new window is displayed and I click anywhere of the Javafx application, I cannot get back to it. I have to close the new window first in order to interact with the original javafx application.
How can I have the ability to open the new window on a button click, while retaining the ability to interact the original javafx application without having to close the new window ?
Button moreInfo = new Button("More Info");
moreInfo.setOnAction(e -> {
MoreInfoDisplayBox.display();
});
public class MoreInfoDisplayBox {
public static void display(){
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("More Info");
window.setMinWidth(400);
window.setMinHeight(400);
window.show();
}
}
The behavior you describe is caused by calling
window.initModality(Modality.APPLICATION_MODAL);
(See docs.)
Instead, just use the default, which you can do explicitly with
window.initModality(Modality.NONE);
or of course just omit that line entirely.

How to addSubWindow to a QMdiArea (set to TAB mode) without taking the focus from the currently active Tab?

I have a function that runs in the background and adds tabs in a QMdiArea. However, when a new tab is added it steals the focus from the currently active tab. Is there a way I can add a new inactive tab (sub window), so I keep the focus to the currently used tab?
I have searched the web but was not able to find anything related to this issue.
I have tried the following:
MyWidget *widget=new MyWidget();
QMdiSubWindow *sub=ui->mdiArea->addSubWindow(widget,Qt::SubWindow);
sub->setWindowState(Qt::WindowNoState);
but it does not have the desired effect.
I got help in another forum and found the solution to that problem:
QMdiSubWindow *previous = ui->mdiArea->activeSubWindow();
QTextEdit *edit=new QTextEdit;
QMdiSubWindow *sub=ui->mdiArea->addSubWindow(edit,Qt::Window)
sub->show();
if (previous==0)
ui->mdiArea->setActiveSubWindow(sub);
else if (previous->isWidgetType()) //I check if previous is widget, because if you close the previous tab, when the new one is opened the program crashes on the next line because previous no longer exists.
ui->mdiArea->setActiveSubWindow(previous);

Xcode Storyboard Modal Transitions & Orientation

So i am fairly new to xcode and loving it so far. I am having a problem adding a new transition between 2 views/scenes in xcode
So i have added the new view to my master detail application and would like the transition to be modal and to be form based. I am having a problem getting my head around the 3 areas where you can add/change the transition of the scene.
I am trying to create a transition similar to the one found in the default apple application when you reply/create a new email.
Currently My application when in landscape and correct button is clicked Jumps to portrait mode and displays my new scene for no reason i can see.
My new scene contains a seague,navigation controller and the scene itself. Any help or suggestions will be greatly appreciated.
So finally figured it out after much playing... I changed the seague to style: modal, presentation: Page sheet, Tansition:Default. So working as expected

Resources