This relates to JavaFX: I have a 'Products' window which contains a TableView filled with a products list, a few buttons (Edit, Delete, Add, Search) and an ImageView with the picture of the currently selected product (this pic changes correctly on click).
Clicking on the 'Edit' button opens a new window where I can change the image file for the product and correctly saves the new pic to the file system (one note here: the new image overwrites the old one, meaning the image path/filename remains the same).
When I close this 'Edit' window, I clean the picture in the ImageView control by doing:
imageView.setImage(null);
and then I set the "new" image:
imageView.setImage(new Image(path));
Setting the image to null efectively removes the old image, however, the imageView container keeps showing the "old picture" after setting the new one. Is there any kind of chache that needs to be cleaned? How can I "tell" the ImageView container that the image has changed, even though the filename is the same?
Thanks for the help, and sorry for my bad english.
After two weeks I finally found the solution:
Instead of saving the new image using the same file name, I now use a new filename, then update the database table and delete the old file from disk.
Images are not longer loaded using imageView.setImage(new Image(path)); Instead, now I load images using:
File img = new File(pathObtainedFromDatabase);
InputStream isImage = (InputStream) new FileInputStream(img);
imageView.setImage(new Image(isImage));
Thanks to all that tried to help.
Related
I'm trying to make an application which switches between scenes back and forth however I need to load a specific AnchorPane's contents into another AnchorPane when the scene switches back. For Example:
In my FXML1, I have a hierarchy that looks like this:
AnchorPane0
----SplitPane
--------AnchorPane1
--------AnchorPane2
In FXML2 the hierarchy is just this:
AnchorPane0
So I load FXML1, then I have a button that switches scenes loading FXML2.AnchorPane0 into FXML1.AnchorPane2. I have a back button in FXML2.AnchorPane0 that needs to load the original scene of FXML1.AnchorPane2 into FXML1.AnchorPane2. Right now my back button loads all 4 containers of FXML1 into FXML1.AnchorPane2. So my questions is, how do I load a specific container's contents preferably without making FXML1.AnchorPane2 its own FXML? Do I need to write a get method for the FXML1.AnchorPane2 to access its contents or is there a way to return an AnchorPane with all of its contents in place already?
I found the solution as shown below:
AnchorPane loader = FXMLLoader.load(getClass().getResource("myFXML.fxml"));
SplitPane spane = (SplitPane) loader.getChildren().get(0);
AnchorPane pane = (AnchorPane) spane.getItems().get(1);
foregroundAnchorPane.getChildren().setAll(pane);
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.
I have a ListView with an ItemsSource that is a List. The viewcell binds some String properties from MyDataModel to labels as well as an ImageSource property to an Image.
The idea is they click the button, select an image from gallery, and the image in the viewcell changes to what they selected.
That all works fine, until they scroll. When the images go off screen, and you scroll back up to them then all of the images show the same image (the last one selected, or rather the first one that appears when scrolling back up).
I realize that it's unloading the image and re-loading it.. but why isn't it getting it from the correct binding source?
Not sure, if I understand your question correct (without code)...
But if you have a ListView bound to a List with a custom ViewCell and want to change some showed data, the following should work:
- first change the data in the list
- then reassign the ViewCell:
lvXX.ItemTemplate = new DataTemplate(typeof(XXyourViewCellxx));
I am doing a project in javafx in which we create forms ( forms like admission form etc)
Form contains many labels,textfields (filled with data from database) and some images.
I want to print these labels, data from textfields and the images in the same layout in which they were created ( I mean, after printing textfield1 should not be in front of label2 etc).
Is is possible? or is it possible to convert this form to pdf file so that it could be printed later?
Thanks.
It is possible to take a snapshot of the Scene:
Scene scene;
WritableImage image = scene.snapshot(null);
And then you can save this image in an image format:
http://java-buddy.blogspot.com/2012/12/save-writableimage-to-file.html
I'm using a modal PopupEditForm to edit rows in my ASPxGridView.
There is an image and upload control inside this form. The old image is being loaded to this ASPxImage for preview and user can upload a new image. But when user does it, even though I change the url of image to new uploaded image url, new image doesn't appear. But if I update the row, it updates the url and shows the new image next time I click to update row.
So there's a problem like PopupEditForm is not being called again. How can I solve this?
First of all, you should learn very good PopupEditForm.
Read and learn this example Grid Editing - Popup Edit Form .
Then If you can't solve your problem, and you have Devexpress licence, you should ask it in Devexpress Support
http://www.devexpress.com/Support/Center/SearchResults.aspx#cD1UNHxQNXwwc2VhcmNodGV4dD1Qb3B1cCBFZGl0IEZvcm0=
Take a look at this code central sample which you can also download and run locally:
http://www.devexpress.com/Support/Center/e/E19.aspx
Btw, Soner points to some good info too.
Thanks.