When I use a TabPane with a touchscreen, the tabs are switching when I swipe left or right, which I want to prevent.
I fixed part of the problem by consuming the swipe events on the child panes, but the tabs still switch when I swipe in the area where the tabs are displayed.
I tried to consume the events that the TabPane generates, such as the swipe and scroll events, but the tabs are still switching. How do I prevent this from happening?
I add the same problem. I solved adding the following filter to the tabPane:
tabPane.addEventFilter(SwipeEvent.ANY, new EventHandler<SwipeEvent>() {
#Override
public void handle(SwipeEvent event) {
event.consume();
}
});
Related
I have a fragment and inside it there is a tablayout with view pager as here.
Each tab opens a bottom sheet fragment, each has a recycler view inside them. I want to make them half open and disable scroll so that once they are opened, their position is fixed and if the user scrolls down they are closed. So they are either half open or closed.
I make them half opened as follows. I tried disabling the scrolling but it was not enough. How can I solve the problem?
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return BottomSheetDialog(requireContext(), theme).apply {
behavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
}
}
I am subclassing QOpenGLWindow (not QGLWidget or QOpenGLWidget) and calling
auto container = QWidget::createWindowContainer(my_opengl_window);
to place it in the layout of a parent QWidget.
The window displays correctly and I can interact with it, but container (and its parent widget) do not receive context menu events when I right-click within my_opengl_window. I do get a context menu if I right-click on the slim margin between the window and its container.
void MyGLWindow::mousePressEvent (QMouseEvent * e)
{
qDebug (__PRETTY_FUNCTION__);
QOpenGLWindow::mousePressEvent (e);
}
The above shows me that my_opengl_window is receiving mouse clicks. I have also tried e->ignore () but still the parent does not receive a context menu event.
Also, setCursor and setToolTip on the container widget have no effect. I suspect this may be related.
How can I get these mouse events to work on a QOpenGLWindow container?
I have a scroll Pane with a rectangle inside the scroll Pane.The rectangle can only move left or right . The scroll pane has a with of 800,when the windows gets to small the scrollbar becomes enabled and you can scroll. My problem is when i try to move the rectangle when the scrollbar is on , the scroll bar will also move either left or right.Is the a way to temporary disable the scroll feature when i am moving the node >
I think what you might be looking for is
public final void setPannable(boolean value)
Sets the value of the property pannable.
Property description:
Specifies whether the user should be able to pan the viewport by using the mouse. If mouse events reach the ScrollPane (that is, if mouse events are not blocked by the contained node or one of its children) then pannable is consulted to determine if the events should be used for panning.
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/ScrollPane.html#setPannable-boolean-
I'm not sure if this works, but sounds like it.
You also could use https://docs.oracle.com/javase/8/javafx/api/javafx/scene/Node.html#onMouseClickedProperty
or a similar MouseProperty, set up a Listener and make it so that when you click on the ScrollPane, it will set https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/ScrollPane.ScrollBarPolicy.html
to NEVER
public static final ScrollPane.ScrollBarPolicy NEVER
Indicates that a scroll bar should never be shown.
then back to your original setting for ScrollPane.onMouseReleased();
Good luck!
I have a HTML editor in a Pane container 355px in width. The editor gets cut on the right side where the width overlaps the containing pane. How can I set the HTML Editor's width to a smaller width than that of the parent container?
Please note that I'm on JavaFx SceneBuilder 2 and dragging the width to something smaller than that of the Parent container just doesn't work.
While on Scene Builder 2.0 the HTML editor can't be resized, this just affects the preview (well, maybe it hiddens some other controls,...). If this is really a problem, instead of adding the HTML editor there, just place a container with a proper fx:id and later on the controller add the editor as a child of that container.
Assuming you have the editor added on your FXML, and the width of your scene is 355px, as you say, the first preview of the application will have the toolbars cut, and there won't be any overflow button until you resize the window. Only then, the toolbars will be resized and the overflows will appear.
To overcome this problems and let the editor be resized right after the application is launched, without the manual resize, the workaround is to find the toolbars of the editor, and resize them.
#FXML private HTMLEditor htmlEditor;
#Override
public void initialize(URL url, ResourceBundle rb) {
Platform.runLater(()->{
htmlEditor.lookupAll("ToolBar")
.forEach(node->((ToolBar)node).setPrefWidth(355));
});
}
Note the hardcoded width value, for the sake of simplicity.
I have a JavaFX 2.2 TilePane with several items (children). I've added css so that on mouse hover, the scale of the item is set to 1.2. By default, the order of children defines what node is drawn first and what last. Is there a way to make hovering item be above all others, without resorting to toFront() and making it be the last item (moving it to the end). This question is similar to https://stackoverflow.com/questions/13893514/scaling-children-in-a-flowpane-makes-the-children-clip-eachother (still unanswered).
Screenshot of the issue is located at: http://vladeck.files.wordpress.com/2013/03/javafx_tilepane.png?w=640
Solution / Workaround
Use a GridPane instead of a TilePane.
When the user clicks on an item in the grid, call toFront on the item.
Sample Code
I added the following code to a calculator which is based on a grid layout which looks similar to the tiled layout in your sample screenshot. With the modified application, I experienced no overlapping of buttons of the calculator. Surprising to me, though they looked a little weird, the scaled buttons made the calculator easier to use...
button.setOnMouseEntered(new EventHandler<MouseEvent>() {
#Override public void handle(MouseEvent mouseEvent) {
button.toFront();
button.setScaleX(1.6); button.setScaleY(1.6);
}
});
button.setOnMouseExited(new EventHandler<MouseEvent>() {
#Override public void handle(MouseEvent mouseEvent) {
button.setScaleX(1); button.setScaleY(1);
}
});
Background
As you note, the overlapping issue is unresolvable in some stock Panes like TilePane. This is because the z-order as well as the relative layout position of a node are both defined by the relative position of the node in the TilePane's child list. In such Panes, you cannot change the z-order and bring it to the front without also moving the node to the last layout position in the TilePane.
A GridPane does not suffer from the same issues as a TilePane because it's child node list order only defines the z-order of it's child nodes, not the layout positioning of those child nodes.
Is there a way (a hack?) to implement my own code of retrieving the children order for drawing when JavaFX repaints TilePanel?
Yes, you could hack the TilePane code if you have the skills.