JavaFX: Application with multiple stage icons - javafx

I m trying to include multiple icons on a JavaFX application primary stage. However, only the first one appears every time but not the other two. the image URLs are right. Just that only a single icon appears. Appreciate any suggestions. Thanks in advance.
primaryStage.setScene(scene);
primaryStage.setMinHeight(1000);
primaryStage.setMinWidth(1000);
for(Type type:Type.values()) {
primaryStage.getIcons().add(new Image(EnergyApp.class.getResource("icons/"+type.iconUrl()).toString(), 24, 24, true, true));
}
primaryStage.show();

Short answer is: This is not working. Perhaps, I couldn't know.
You just set a single image. For example:
stage.getIcons().add(new Image("file:icon.png"));

Related

Javafx working with the same window problem

What I am trying to do:
I have menu and and after click I am trying to remove unnecessary TextFields.
What I did:
I used this example:
"In JavaFX, nodes can simply be removed from a Parent (e.g. an AnchorPane) using .getChildren() following by .remove(Object o)
AnchorPane ap;
ap.getChildren().remove(btn);
I tried to use:
FXMLLoader load=new FXMLLoader(getClass().getResource("LoginRegister.fxml"));
Parent root = load.load();
root.getChildren();
But my root does not have getChildren() function.
Where could be the problem?
Thank you in advance.
EDIT: FOUND THE ANSWER HERE: How to access UI components from SceneBuilder in JavaFX
WHAT I DID WRONG: I USED IN FXML FILE AND IN CONTROLLER DIFFERENT FX:ID's

Issue creating button in which opens a window/stage

Im having issues with understanding what should be the model in my ViewLoader statement while making a JavaFXML MVC project
I have a button on the main menu in which when the user clicks it will take me to another window called known as the build menu.
Ive tried a multitude of possible models that I think would work including getBuild etc.
https://imgur.com/Ubz43CI
Here is a screenshot of my Controller and View file
https://imgur.com/0C3FUG3
Here is a screenshot of my Model file
The expected result based off a similar project ive found online is that when the button is clicked a new window pops up. Im assuming the reason this doesnt work is because the getBuild method/statement needs to be initialised in the Controller class however I am unsure as of how to do that as getBuild is a method in my Model class
If you are only Navigating from one scene (window) to another the code is as listed below. Why do you think you need to have a MVC pattern to do this is is confusing.
Here is the code to go from one scene to another we name all our Anchor Pane's somenamePane so we know where we are and where we are going.
public void goTO() throws IOException, SQLException{
stage = (Stage)paneStart.getScene().getWindow();// pane you are ON
ckbookPane = FXMLLoader.load(getClass().getResource("manager.fxml"));// pane you are GOING TO
Scene scene = new Scene(ckbookPane);// pane you are GOING TO
scene.getStylesheets().add(getClass().getResource("checkbook.css").toExternalForm());
stage.setScene(scene);
stage.setTitle("Check Book Manager");
stage.show();
stage.sizeToScene();
stage.centerOnScreen();
}

Javafx: write code only for a part of a fxml interface

I know my title is a little too generic, but I sincerely have no idea how to ask it. So, the topic is JavaFX. I have a part of the interface coming from a fxml file and another part that I'd like to code manually. So my question is, more specifically, is there a way to insert a sort of pane into another, coming from scene builder? If you have "questions about my question", please, ask me!
Ok, I managed to dynamically add a label on button click, thanks to your suggestions.
Anyway, i tried to add imageviews, but i get a lot of error! This is my code:
ImageView pages[] = new ImageView[8];
for (int i=0; i<8; i++) {
pages[i] = new ImageView(new Image(FlowLayout.class.getResourceAsStream("src/provaProgetto/Penguins.jpg")));
base.getChildren().add(pages[i]);
}
What's wrong?

Collapsing Toolbar Layout always expanded when returned from fragment

I have 2 fragments (Fragment A and Fragment B) both with collapsing toolbar layouts and corresponding recyclerviews within a coordinatorlayout.
If I scroll up in my recyclerview (so the CollapsingToolbarLayout has collapsed) and then open Fragment B from fragment A (Pushing A onto the backstack).
When I return to fragment A by hitting back. The CollapsingToolbarLayout/AppBarLayout is always expanded, even though the recycler view is in the same position.
Anyone experience this?
There's a issue related to this.
According to Chris Banes.
Add these lines inside onViewCreated() of your fragment to solve the issue.
ViewCompat.requestApplyInsets(mCoordinatorLayout);
It's an old question but none of the answers it's correct. I found this other question where they fixed the problem:
How to restore Collapsing Toolbar Layout State after screen orientation change
You have to set an id to your views in order to restore their state automatically.
I had face same problem so i write below code:-
private boolean isExpand = true;
private void setTitleNotExpand(boolean isExpand) {
if(getFragmentViewHolder() != null) {
this.isExpand = isExpand;
// AppBarLayout variable
getFragmentViewHolder().appbar.setExpanded(isExpand);
}
}
when you do add back stack then write below code :-
// write below code where you want to stick your toolbar
setTitleNotExpand(false);
// write below code where you want not to stick your toolbar
setTitleNotExpand(true);
on your onFragmentViewHolderCreated write below code :-
getFragmentViewHolder().appbar.setExpanded(isExpand);
another thing to consider is that views cannot restore their state if they don't have an id
Today, to fix this issue you only have to set an id to your coordinator layout to fix this.

How to implement SplashScreen in SAPUI5

Does anybody here knows how to implement a Splash Screen in SAPUI5? I have tried creating a page so that it would be the default page once the application is loaded, but there was an issue as to how to make it the default page even if another page is bookmarked. So what we did was use an image as the Splash Screen. Now the problem is the size of the image based on the device used.
Do you have any idea how we can implement this? Any idea would be of great help. Thank you so much! :)
Maybe Dialog control will fit your need?
Here is an example:
var oButton = new sap.m.Button({
text: "Hit Me To See Splashscreen",
press: function(){
var oDialog = new sap.m.Dialog({
stretch: true,
content:[
new sap.m.Text({text:"This is Splashscreen! Click Anywhere To Close the Splashscreen."})
]
}).attachBrowserEvent("click", function(){oDialog.destroy();});
oDialog.open();
}
}).placeAt("content");
And here is a working JSBIN example: LINK
I guess what you are looking for is a loading Animation on startup while loading libraries or backend-data: checkout this one, perfect guide! http://openui5.blogspot.com/2014/04/splash-screen.html
Thank you for your responses. I highly appreciate it. :)
Anyways, i didn't use an image nor a separate page. I just added a separate div in index.html which contains the image and the text. I added a script that will hide the div once the DOM Content is loaded.
document.addEventListener("DOMContentLoaded", function(){
document.getElementById("splashScreen").style.display = "none";
document.getElementById("content").style.display = "block";
});

Resources