Make JavaFx application Fullscreen OnClick - javafx

Hello i am making a web browser in javafx and i want to make it fullscreen when user clicks on Fullscreen button. I tried the below given code but unfortunately it is giving error.
Fullscreen.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
primaryStage.setFullScreen(true); // here it gives error "cannot find variable primaryStage"
}
});
**I know that this doesn't follow the basics of java but i didn't find another way of implementing it.
Kindly help :)

Assuming Fullscreen is a button, just get the stage it's in with
((Stage)Fullscreen.getScene().getWindow()).setFullScreen(true);

Related

JavaFx WebView - how to scroll it to the bottom

I have made a conversation stage in JavaFx with a WebView that is displaying whole conversation. I want to show it from the bottom where the newest messages are so I used a function "execute script":
public void initialize() throws SQLException
{
buildText();
conversationText.getEngine().loadContent(text1);
conversationText.getEngine().executeScript("window.scrollTo(0, document.body.scrollHeight);");
conversationText.getEngine().setUserStyleSheetLocation(getClass().getResource("/html/style.css").toExternalForm());
}
I wrote this function in an initialize() void but it doesn't work, when I open the conversation it shows me all from the top where the eldest messages are :
But what is interesting it works properly when I use this metod form a void that is connected with a button named "script"
public void script()
{
conversationText.getEngine().executeScript("window.scrollTo(0, document.body.scrollHeight);");
}
when I press this button it scrolls to the bottom :
Is there any way to do this correct in an initialize void ? I have tried many ways like inserting the button method script() into initialize but i noticed that if I use function webengine.loadcontent() it always displays me all from the top.
I want to show the user the newest messages at the bottom from the beginning , not after pushing a button.

Android TV: Disable collapsing on info_field on ImageCardView

I'm working with Android TV for the first time and I'm learning to use Leanback by modifying the example tv app that is provided.
The issue I'm having is that when I press left on the first item in the lists the navigation drawer opens and focus goes to the headers in the navigation drawer. When this happens, the info_field view in the ImageCardViews collapse behind the image.
What happens: The info field on the ImageCardView hides when I open the navigation drawer.
What I want to Happen: The info field remains visible when I open the navigation drawer.
I'm sure there's a way to do this because I've seen it in some Android TV apps, like Twitch. What's the best way to have the info_field visible when the navigation drawer is open?
I've worked out how to do it. In the CardPresenter, in onCreateViewHolder, when creating the ImageCardView I've overridden the BaseCardView method, setActivated(boolean activated) to always pass 'true' into it's super. And then call setActivated so that it's activated from the beginning. Like this:
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
ImageCardView cardView = new ImageCardView(parent.getContext()) {
#Override
public void setActivated(boolean activated) {
super.setActivated(true);
}
#Override
public void setSelected(boolean selected) {
updateCardBackgroundColor(this, selected);
super.setSelected(selected);
}
};
cardView.setActivated(true);
cardView.setFocusable(true);
cardView.setFocusableInTouchMode(true);
return new ViewHolder(cardView)
}
So that did the trick for me. The ImageCardView never collapses.
I think if you look at this SO post you'll get most of the way there. The info view hides due to what leanback calls "expanding".
Try just calling enableMainFragmentScaling(false); in your BrowseFragment and see if that does what you want. If it doesn't feel like exactly what you want, refer to the post I linked to.
Additionally, if you've tried what I recommend in the linked SO post, you could also call the API on the BaseCardView setInfoVisibility() and pass it CARD_REGION_VISIBLE_ALWAYS. This just requires calling on a reference to your card which shouldn't need an override of the Presenter or Card.

NavigateToViewModel with Caliburn Micro 2 and Windows Phone 8.1

I'm trying to figure out how to successfully get Caliburn Micro to navigate from one page to another in a Windows Phone 8.1 app.
My first page loads just fine, as specified in my App class:
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
this.DisplayRootViewFor<HomeViewModel>();
}
This launches the HomeView without issue. On that view I have a button that calls the following method:
public void GoToPage2()
{
this.navigationService.NavigateToViewModel<Page2ViewModel>();
}
This method is called when the button is pressed and the constructor for Page2ViewModel is called as well. The page just never displays and I can't figure out why. I feel like I'm missing a core concept, but I can't find any examples of how this should work.
Thanks for any help.
The solution is odd, and perhaps a bug in Caliburn Micro. In the OnLaunched method I used to have:
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
this.DisplayRootViewFor<HomeViewModel>();
}
This worked and launched the home view, but subsequent navigation never worked. After comparing to a sample application I found, I changed the code to:
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
this.DisplayRootView<HomeView>();
}
This also displays the home view, but now subsequent navigation works! I'm not sure why this would be the case, but at least I have an answer.

Refreshing tableView in JavaFx after closing dialog

I have two layouts in JavaFX app. The first one contains table view whereas the second one is a simple dialog to input data. The problem is that I want to refresh data after closing the dialog. Now I have a button on the first layout which refreshes data:
data.removeAll(data);
loadDataToTable();
But I don't want to invoke methods shown above with the button but automatically right after closing the dialog. I don't know how to make this, let's say, connection between those controllers.
thanks in advance
The new Dialog, if I am not wrong must be a new Stage ! Let us consider the new Stage to be modifyStage. We can call the onSetCloseRequest of the new Stage and put your code in it.
modifyStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
#Override
public void handle(WindowEvent paramT) {
data.removeAll(data);
loadDataToTable();
}
});

Eclipse Rap no focus on a button

I have a problem with Focusable Buttons on Eclipse Rap. I have defined some Toogle buttons with some css style when your mouse is over it, with it is selected and when it is not. The thing is the focus on the button is making it look odd.
I have tried
btnAnimals = new Button(panel, SWT.TOGGLE | SWT.NO_FOCUS);
with no exit. And finally I decided to implement a FocusAdapter for the buttons:
FocusListener focusListener = new FocusAdapter() {
#Override
public void focusGained(FocusEvent event) {
txtStreet.setFocus();
}
};
btnAnimals.addFocusListener(focusListener);
The strange issue that this listener is only called ONCE. Do you know what I am doing wrong? Is it a bug?
Thanks in advance
After asking in Eclipse Rap Forum, they give me the propper answer and it is to use RWT Theming:
Button-FocusIndicator {
border: none;
}
Hope that helps ;)

Resources