All dialog windows can be moved off screen (horizontally or vertically, doesn't matter). When this window is behind screen, one can continue dragging it further and the content of the screen will move.
It sounds difficult to understand, but at the end it looks like this:
The following changes in css don't help a lot:
body {
...
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
overflow-y: hidden;
overflow-x: hidden;
...
}
html {
overflow-y: hidden;
background-color: transparent;
}
Vertical and horizontal scroll bars don't appear when dialog window is moved there. But if there's a dialog window that has greater size than main screen, scroll bars also won't appear - and this is another problem.
How to prevent dialog window from moving off screen (fast example, dialog windows in google drive - they only move in visible part of screen)?
I came to solution I was looking for by overriding endDragging method of DialogBox. Here it is:
#Override
protected void endDragging(MouseUpEvent event)
{
//Move dialog window behind top border
if(this.getAbsoluteTop() < 0) {
this.setPopupPosition(this.getPopupLeft(), 0);
}
//Move dialog window behind bottom border
if(this.getAbsoluteTop() > (Window.getClientHeight() - this.getOffsetHeight())) {
this.setPopupPosition(this.getPopupLeft(), Window.getClientHeight() - this.getOffsetHeight());
}
//Move dialog window behind left border
if(this.getAbsoluteLeft() < 0) {
this.setPopupPosition(0, this.getPopupTop());
}
//Move dialog window behind right border
if(this.getAbsoluteLeft() > (Window.getClientWidth() - this.getOffsetWidth())) {
this.setPopupPosition(Window.getClientWidth() - this.getOffsetWidth(), this.getPopupTop());
}
super.endDragging(event);
}
When dialog box is moved off the screen, it appears in visible part of the screen after mouse release. One can improve it and override continueDragging in order to prevent window from moving off screen at all.
Related
I'm having a problem handling the focus of a child Node. I have this custom layout with a bunch of nodes in its hierarchy, and I'd like to make one of its children (specifically, a Pane) to be focusTraversable or can obtain focus on mouse pressed (like a button control). What I really want to do is simply change the background color of the child when focused, here's my code:
Pane pane = new Pane();
pane.getStyleClass().setAll("container");
pane.setFocusTraversable(true);
pane.setOnMousePressed(event -> {
if (!pane.isFocused() && pane.isFocusTraversable()) {
pane.requestFocus();
// Test if this node is currently focused
System.out.println(pane.isFocused());
}
});
CSS changes the -fx-background-color of the pane:
.container {
-fx-background-color: red;
}
.container:focused {
-fx-background-color: blue;
}
Although it appears that the node is focused when traversing using TAB key, the background does not change at all when it is pressed. So, what was the proper way of handling focus of children?
Am hoping someone can advise what is need to be changed to remove the hideous border (?) from this menu (see image).
Have extracted modena from the java jar to see how they do it but to no avail. Sure it's very very simple just drawing a blank at the moment.
The css at the moment is very simple just not sure which element need to be changed / added.
.menu-bar {
-fx-background-color:#237a72;
/*-fx-border-width:2;*/
}
.menu-bar .label {
-fx-text-fill:#ffffff;
}
.menu-bar .label:hover {
-fx-text-fill:yellow;
}
.menu-item {
-fx-background-color:#237a72;
-fx-border-color: #237a72;
}
Many Thanks.
The white border is the background color of the context-menu.
So if you want to get rid of it, you could remove the padding:
.context-menu {
-fx-padding: 0;
}
I have a popup window that is launched with a WxL dimension, where W = width, and L = length.
The content fits well in that area for a few screens. However, in some cases (views that appear conditionally), the window size is not big enough and ends up showing a scrollbar.
The ask here is - How can we auto-adjust the popup window size so that it resizes itself (based on the content), and hence avoid the scrollbar in all cases.
One crude option is to get the max size of all possible views that can appear within the window and always (pre)set that as the size of the window, i.e., something like (W+w)x(L+l). However, that's not ideal/preferable since some of the views do not have much content in them and would look awkward with a larger popup size.
Working demo
$(function(){
$(window).resize(function(){
// get the screen height and width
var maskHeight = $(window).height();
var maskWidth = $(window).width();
// calculate the values for center alignment
var dialogTop = (maskHeight - $('#dialog-box').height())/2;
var dialogLeft = (maskWidth - $('#dialog-box').width())/2;
// assign values to the overlay and dialog box
$('#dialog-overlay').css({ height:$(document).height(), width:$(document).width() }).show();
$('#dialog-box').css({ top: dialogTop, left: dialogLeft, position:"fixed"}).show();
}).resize();
});
i am developing a GWT mobile application with GWT 2.4. i want my DialogBox to be seen always on the center of the user's viewport on zoom or on normal view. On normal view, center() can handle it but when the page is zoom, the DialogBox pops on center of the whole browser window which includes the scroll part of the page not on the center of the user's viewport. how to do this? please help. thanks in advance.
You need to attach a handler to your window that catches the zoom event. In this handler, you call
myDialogBox.setPopupPosition((Window.getClientWidth() - myDialogBox.getOffsetWidth())/2, (Window.getClientHeight() - myDialogBox.getOffsetHeight())/2);
}
You may need to add a check for situations when your dialog is bigger than the browser window, if you want to treat them differently.
i have to implements ResizeHandler on my window and on its constructor, i have added ResizeEvent handler > Window.addResizeHandler(this);. since i'm implementing the ResizeHandler interface, i need to override the following:
#Override
public void onResize(ResizeEvent event) {
if (isShowing() ) { //check if popup is showing
int left = (Window.getClientWidth() * 0.5 - (widthOfMyWindow * 0.5) );
int top = (Window.getClientHeight() * 0.5 - (heightOfMyWindow * 0.5) );
setPopupPosition( left < 10 ? 10 : left, top < 0 ? 0 : top );
}
}
Is there any way to get mouse coordinates on a click of desktop screen, i dont want to click inside the java frame, want to click the mouse pointer straight away on desktop and have to know the x,y coordinates ? please help me out? (windows)
Rectangle rectScreenSize = new Rectangle(x1,y1,x2,y2);
BufferedImage biScreen = robot.createScreenCapture (rectScreenSize);
finally want to pass the coordinates for rectangle, to determine the screen size for robot class?
You can make a transparent, undecorated JFrame on top of everything, and pass the click on with the Robot class.
By the way, the following does not work outside your own window (I had hoped so):
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
#Override
public void eventDispatched(AWTEvent event) {
System.out.println("event: " + event);
if (event.toString().contains("MOUSE_EXITED")) {
System.out.println("mouse_exited");
}
}
}, AWTEvent.MOUSE_EVENT_MASK);