Disable HTML based scrolling webview javafx - javafx

Im using a custom webview to display my text i made with htmleditor.
The custom webview adjusts the size of the webview so the text fits almost perfectly in it.
I make the webview "throw" its scrollEvent to the scrollpane with vbox in it it, so its not handled by the webview itself.
But still i see the text scroll up and down a bit inside the custom webview when i scroll over it. I read on some other post its the HTML itself that handles the scrolling. But i have no idea how to disable that.
webView.setOnScroll(new EventHandler<ScrollEvent>() {
#Override
public void handle(ScrollEvent scrollEvent) {
vBox.getOnScroll().handle(scrollEvent);
scrollEvent.consume();
}
});

Well for what I understood you don´t want the scrollbar to move your page
Set the scroll bar invisible
scrollBar.setVisible(false);
Disable the scrollbar, so on move the event won´t happen
scrollPane.addEventFilter(ScrollEvent.SCROLL,new EventHandler<ScrollEvent>() {
#Override
public void handle(ScrollEvent event) {
if (event.getDeltaX() != 0) {
event.consume();
}
}
});
Or you can use scroll panes, and set them to fit.
scrollPane.setFitToHeight(true);
scrollPane.setFitToWidth(true);
Hope any of these would help.

Related

JavaFx - Table view not scrolling on Mouse Wheel ( disable Scrolling of Table View ), When put Table Cell a webview

My scenario is I am using a webview one of the columns cell of the Table view, So, When I scroll mouse wheel on that column, table view Scrolling not fired, But, web View move something up and down, That means web View got the mouse scrolling, and for that reason table view is not scrolling.
So, My question is, is there any Solution that, on mouse scrolling, upon the webview, fire the table view scrolling behaviour, and that time stopped the scrolling behaviour of web view ?
#Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
} else {
updateTextFlow(highlightText.getValue());
setGraphic(webView);
//setGraphic(textFlow);
}
}
At last I have got the idea on of So Answer. What I did :
ScrollBar scrollBar = (ScrollBar) tableView.lookup(".scroll-bar:vertical");
webView.addEventFilter(ScrollEvent.SCROLL, new EventHandler<ScrollEvent>() {
#Override
public void handle(ScrollEvent event) {
event.consume();
Node target = scrollBar;
ScrollEvent retargettedScrollEvent = new ScrollEvent(target, target, event.getEventType(),
event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), event.isShiftDown(),
event.isControlDown(), event.isAltDown(), event.isMetaDown(), event.isDirect(),
event.isInertia(), event.getDeltaX(), event.getDeltaY(), event.getTotalDeltaX(),
event.getTotalDeltaY(), event.getTextDeltaXUnits(), event.getTextDeltaX(),
event.getTextDeltaYUnits(), event.getTextDeltaY(), event.getTouchCount(),
event.getPickResult());
// Event.fireEvent(target, retargettedScrollEvent);
javafx.event.Event.fireEvent(target, retargettedScrollEvent);
// System.out.println("webView.addEventFilter------------");
}
});
At that way, when I scroll upon the webview, The Whole tableView Start Scrolling, Alhamdulillah.

HOWTO: Manipulate Back Arrow Icon and Button on Navigation Bar (Xamarin Forms / Android)

I am attempting to change the size of the back arrow in the navigation bar.
Using information from this article, I have added the following code:
protected override Task<bool> OnPushAsync(Page view, bool animated)
{
var result = base.OnPushAsync(view, animated);
var activity = (Activity) Context;
var toolbar = activity.FindViewById<Toolbar>(Resource.Id.toolbar);
if (toolbar != null)
{
if (toolbar.NavigationIcon != null)
{
if (toolbar.NavigationIcon is DrawerArrowDrawable navigationIcon)
{
// Code goes here?
}
}
}
return result;
}
If this is indeed the correct path, what code goes in the area marked by the comment "Code goes here?"?
* UPDATE *
I realized that what I am trying to figure out was not exactly described in my original question.
More specifically, when I mentioned that I am trying to resize the navigation bar back arrow, what I am really trying to do is to resize the button that the icon appears on.
For example, if I shrink the height of the navigation bar using code like the following:
On<Android>().SetBarHeight(100);
The button that the icon appears on will be clipped.
Ultimately, what I am trying to accomplish is resizing the icon AND the button that the icon appears on. I have already figured out how to do the former.
I am attempting to change the size of the back arrow in the navigation bar.
If you want to change size of the back button in the navigation bar, you can get new icon from Drawable in resource for toolbar.NavigationIcon.
public class NavigationPageRenderer : Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer
{
public AppCompToolbar toolbar;
public Activity context;
protected override Task<bool> OnPushAsync(Page view, bool animated)
{
var retVal = base.OnPushAsync(view, animated);
context = (Activity)Forms.Context;
toolbar = context.FindViewById<AppCompToolbar>(Droid.Resource.Id.toolbar);
if (toolbar != null)
{
if (toolbar.NavigationIcon != null)
{
if (toolbar.NavigationIcon is DrawerArrowDrawable navigationIcon)
{
// Code goes here?
toolbar.NavigationIcon = Android.Support.V7.Content.Res.AppCompatResources.GetDrawable(context, Resource.Drawable.back);
toolbar.Title = "Back";
}
}
}
return retVal;
}
}
Here is the sample you can take a look:
https://github.com/hachi1030-Allen/XamarinCustomNavBar
<NavigationPage.TitleView> will help you out there. This is a XAML approach.
Example:
<NavigationPage.TitleView>
<StackLayout>
....
</StackLayout>
</NavigationPage.TitleView>
Using this approach you will be able to set HeightRequest and WidthRequest of whatever element you place inside the StackLayout and whatever else you want to amend.
Also, note that if you are having icon size problems it may be worth looking into whether or not your drawable/ icons are the right size for the right resolution.

javafx how to center scrollpane content?

I've a tabview that contains a scrollPane, and a scrolPane contains nodes.
I added a button fit, i want when i click in this button the content of the scrollpane will be centered, I dont know how to do this
#FXML protected void onFitClicked(ActionEvent event)
{
//calling the method that centers the content of the scrollpane
fit();
}
that's what i've done until now .. :( i'll be happy for any help
public void fit()
{
m_scrollPane.setFitToWidth(true);
m_scrollPane.setFitToHeight(true);
}
Try
m_scrollPane.setHvalue(0.5);
m_scrollPane.setVvalue(0.5);

Javafx Disable Scrolling by Mousewheel in ScrollPane

Does anayone know how to disable scrolling by Mousewheel in a ScrollPane?
The following works for me:
scrollPane.addEventFilter(ScrollEvent.ANY, new EventHandler<ScrollEvent>() {
#Override
public void handle(ScrollEvent event) {
if (event.getDeltaY() > 0) {
zoomIn();
} else {
zoomOut();
}
event.consume();
}});
You may find that you also need something like the following:
scrollPane.setOnScroll(new EventHandler<ScrollEvent>() {
#Override
public void handle(ScrollEvent event) {
if (event.getDeltaY() > 0) {
zoomIn();
} else {
zoomOut();
}
event.consume();
}
});
I added the above elaboration to another answer in this thread, but it hasn't shown up in the public feed from what I can tell. So, I've pasted it in its own answer.
This question is a bit of a duplicate, but it showed up in Google for me first, so I'm answering it. The inspiration for the above is:
Zooming in JavaFx: ScrollEvent is consumed when content size exceeds ScrollPane viewport
I think there is no direct solution.
So I would add an event filter to the ScrollPane for the SCROLL EventType and consume every event. That should prevent any mouse generated scroll events from being delegated to the ScrollPane.

vertical scrollBar in JavaFX TableView should be down when it appear first time

Using JavaFX I am rendering huge amount of rows in tableView. So My requirement is that when the tableview renders the vertical scrollbar should be down. I created this with the help of scrollTo(). But after that I am not able to scroll the tableView. Its always coming down and not able to see the previous view.
Platform.runLater(new Runnable() {
#Override
public void run() {
int n = dataTable.getItems().size();
if (n > 10)
dataTable.scrollTo(n);
}
});
Does anyone have any idea what to do?

Resources