I'm working with JavaFX. I need to know how to check contains of ImageView.
E.g. If I have image inside ImageView I should recive information "true" if not "false", and the most important things - If this ImageView is empty how I can create 'if' conditions ?
You can check, if the image property is null. Now you may also want to consider a Image to be empty where the image could not successfully be loaded to be empty, which could be done using the following method:
public static boolean isEmpty(ImageView imageView) {
Image image = imageView.getImage();
return image == null || image.isError();
}
A thing you may also want to check is the width and height of the image.
Related
If a ContextMenu has lots of items, it fills the entire screen. It seems that ContextMenu.setMaxSize has no effect whatsoever.
Is there a way to restrict the size of a ContextMenu, in a way that it is still scrollable via mouse wheel & and the up and down buttons appear?
I guess I could roll my own control with VBox & Scrollpane, but I'd like to avoid this if possible.
Unfortunately, limiting the size of popup is not supported: the Region that's responsible for showing the MenuItems is ContextMenuContent and implements its computeMaxHeight to return the screenHeight. That container is created by ContextMenuSkin and stored into a private final field, so there's no way to replace it with a custom implementation with a more intelligent implementation.
What we can do, though, is to access that region and set its maxHeight to the same value as the ContextMenu. To remain off the evil illegal reflective access to the private field, we can register a handler for the Menu.ON_SHOWING event and update the size as needed [*].
Something like
public class MaxSizedContextMenu extends ContextMenu {
public MaxSizedContextMenu() {
addEventHandler(Menu.ON_SHOWING, e -> {
Node content = getSkin().getNode();
if (content instanceof Region) {
((Region) content).setMaxHeight(getMaxHeight());
}
});
}
}
[*] update: to make this work, the ContextMenu must have a reasonable maxHeight (default is Double.MAX_VALUE), that is it must be set manually after instantiation. Furthermore, we have to use the ContextMenu's maxHeight in the eventHandler (vs. f.i. an arbitrary constant), otherwise vertical location of the popup is broken - the layout code still thinking, that it's filling the entire screen height.
ContextMenu menu = new MaxSizedContextMenu();
menu.setMaxHeight(200);
I'm using ImageView ( javafx ), I tried to load an image (jpg), it works, and when i try to load another it is not (I tried gif, png, also another jpg). I also tried to change the name of the image loaded before, and same, it doesn't load.
It just work with the first image, with same name.
I declared this :
#FXML
private ImageView imageView;
AND this is the code that worked:
InputStream is = this.mainApp.getClass().getResourceAsStream("..\\resources\\images\\facture\\recuBank\\2015\\22-12-2015\\12080351_10206938666998884_3823913475123618229_o.jpg");
if(is != null)
{
Image img = new Image(is);
this.imageView.setImage(img);
}
AND this doens't worked :
// I renamed the first image
InputStream is = this.mainApp.getClass().getResourceAsStream("..\\resources\\images\\facture\\recuBank\\2015\\22-12-2015\\a.jpg");
if(is != null)
{
Image img = new Image(is);
this.imageView.setImage(img);
}
Hope someone can help
WOW I solved it just by doing a REFRESH in folder "resources", in my project (in Eclise).
I was adding the images directly in the folder, so in my project, Eclise is not aware that any change happened.
(There already is a question regarding this but it has no answer and the comment isn't helpful either.)
I've got a TableView and I'd like to have a column with multiline labels that I can edit. Ideally, the behaviour would be like a TextFieldTableCell but with multiline support:
It displays text like a label.
When clicked, it transforms into a TextField (or in this case, a TextArea) so the text can be edited.
I haven't found a solution for this yet. The only workaround I've got right now is put a TextArea as the cell's "graphic":
descriptionTableColumn.setCellFactory(param -> new TableCell<Attachment, String>() {
#Override
protected void updateItem(String item, boolean empty) {
if (empty) {
setGraphic(null);
} else {
TextArea area = new TextArea(item);
area.setMinHeight(USE_COMPUTED_SIZE);
area.setPrefHeight(USE_COMPUTED_SIZE);
area.setMaxHeight(USE_COMPUTED_SIZE);
setGraphic(area);
}
}
});
(Code to listen to the text changes is missing here; it doesn't trigger the OnEditCommit event.)
However, the TextArea is always rendered as a normal TextArea with a border and white background. I can live with that. But the area also always renders with a certain height (about 180px) even when it's empty, even though I set USE_COMPUTED_SIZE.
So the question is:
Is there a way to get the ideal behaviour, similar to the TextFieldTableCell?
If not, is there a way to have the TextArea only use as much height as needed?
Ok, the basic idea is to copy the TextFieldTableColumn and adjust its behavior to create a TextAreaTableColumn. I hacked a small working example implementation together: https://gist.github.com/eckig/30abf0d7d51b7756c2e7
Usage:
TableColumn<?, ?> column = new TableColumn<>();
column.setCellValueFactory(...);
column.setCellFactory(TextAreaTableCell.forTableColumn()); // add StringConverter if neccessary
tableView.getColumns().add(column);
But, there are still some things left which need to be implemented / some tuning:
Adjust prefRowCount to show only the necessary amount of rows.
Maybe adjust prefColumnCount?
Because the "Enter" Key gets consumed for a new-line, I had to add a Save Button to commit the edit. This is somewhat ugly, but for now I do not have a better idea.
But hopefully you get the idea ;-)
I have a page that displays data about an object. At the top of the page is room for an icon, showing a picture of that object. Tapping this icon brings up a new page that allows the user to take a new picture, and save it as a temporary new picture for the object (not put in database, but should persist for the session)
Initial page:
private var source:Object = new Object();
protected function onInitialize():void {
source = navigator.poppedViewReturnedObject;
}
When setting source for the image later...
if (source != null) {
pic.source = source.object;
}
else {
pic.source = "no_picture_available_image.png";
}
2nd Page (User can take picture, and view new picture):
[Bindable]
private var imageSource:Object = null;
<s:Image id="pic" width="90%" height="75%" horizontalCenter="0" source="{imageSource}" />
After taking picture...
protected function mediaPromiseLoaded(evt:Event):void {
var loaderInfo:LoaderInfo = evt.target as LoaderInfo;
imageSource = loaderInfo.loader;
}
This does show the picture just taken correctly on this page.
To get back to old page, i use navigator.popView, and use:
override public function createReturnObject():Object {
return imageSource;
}
Unfortunately, it doesn't work. The imageSource isn't null when it is read from navigator.poppedViewReturnedObject, but no image is shown.
Does the LoaderInfo not persist after popping the view? Are the camera pics not automatically saved? I can't find answers to any of these questions, and I can't debug using the phone in my current environment.
After thinking about this a bit, don't return LoaderInfo.loader as the poppedViewReturnedObject. If I remember correctly, a DisplayObject can only be set as the source of one Image. Instead, return LoaderInfo.loader.content.bitmapData. That BitmapData should be the raw data used to display the image. This data can be used repeatedly to create images and can be set as the source of an Image.
Problem turned out to be in my first page's image declaration - I didn't set a width. Seemingly, the object being displayed couldn't handle not having a specified width.
Note that passing back the loader did work fine.
I'm trying to scroll down to the bottom of a grid, after the model was setted.
1) I set the model:
myGrid.setModel(new ListModelList<Object>(myList));
2) I override the row renderer
myGrid.setRowRenderer(new RowRenderer<Object>() {
#Override
public synchronized void render(Row row,final Object data, int index) throws Exception {
row.setStyle("commonCellPadding");
.
.
.
row.appendChild(htmlMessage);
}
});
3) Finally if the list used to set the model is too big (the grid in the .zul has fixed height) i want to show the last results (the more recents in this case).
I need to scroll down automatically after the render. How can i do this?
Things i had try
a) Calling a javascript function after the render, this doesn't work due to the fact that the gridEle.scrollHeight attribute returns the fixed height of the grid setted in the zul (or 0 if not) and not the grid's height after the model was setted.
myGrid.addEventListener(ZulEvents.ON_AFTER_RENDER, new EventListener<Event>() {
public void onEvent(Event event) throws Exception
{
Clients.evalJavaScript("var gridEle = document.getElementById('"+myGrid.getUuid()+"-body"+"'); gridEle.scrollTop = gridEle.scrollHeight;alert(gridEle.scrollHeight);");
}
});
Why don't you sort the myList descending at first to make the last row become the first one instead to control the scroll bar?
In my opinion, it would be more easy and matching the users experience.
Just call Clients.scrollIntoView(rows.getLastChild()); after you have set the model and row renderer (provided rows is Rows component id and is already auto wired into your controller). See the live demo on zkfiddle here and source
UPDATE: Clients.scrollIntoView(Component) wouldn't work if you are using Render-On-Demand feature because naturally if the row that you want to scroll to wouldn't have been loaded on initial page load.