JavaFX popup hidden when stage is in fullscreen mode - popup

I am trying to popup a dialog over my fullscreen primary stage in javafx. When I create my popup, it is unexpectedly hidden behind my fullscreen primary stage until the stage is removed from fullscreen mode (via ESC). If I make my primary stage maximized and undecorated instead of fullscreen, then my popup will appear on top of the primary stage as expected.
Am I missing something about how fullscreen mode is different than maximized and undecorated mode? Am I using fullscreen mode improperly?
I am using java version 1.8.0_20 on CentOS 6.5 with Gnome.
Here is my SSCCE:
import javafx.application.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.stage.*;
public class TestApplication extends Application {
private Stage primaryStage;
public static void main(String[] arguments) {
launch(arguments);
}
public void start(Stage stage) {
this.primaryStage = stage;
// Create a fullscreen primary stage.
primaryStage.setTitle("Main Stage");
primaryStage.setScene(new Scene(createRoot()));
primaryStage.setFullScreen(true);
primaryStage.show();
}
private Parent createRoot() {
Button button = new Button("Show popup");
button.setOnAction((event) -> showPopup());
return button;
}
private void showPopup() {
// Create a popup that should be on top of the primary stage.
Stage popupStage = new Stage();
popupStage.setScene(new Scene(createPopupRoot()));
popupStage.setTitle("Popup Stage");
popupStage.initModality(Modality.WINDOW_MODAL);
popupStage.initOwner(primaryStage);
popupStage.show();
}
private Parent createPopupRoot() {
return new Label("This is a popup!");
}
}

After repeating this problem with java version '1.8.0_40', I finally found how to fix this problem!
popupStage.initStyle(StageStyle.UTILITY);
Stage.initStyle(StageStyle) -- JavaFX 8
Giving the popup a style of StageStyle.UTILITY seems to keep the popup in front of the fullscreen window even when clicking outside of the popup.
I saw this same issue when using the new Alert class in java 1.8.0_40, and setting the style to StageStyle.UTILITY fixed that as well (Dialog.initStyle(StageStyle) -- JavaFX 8).
I don't know why this works.
Side Note:
It looks like removing the call to popupStage.initOwner(...) allows the popup to appear above the full screen application, but clicking outside of the popup causes the popup to disappear.

Assuming you're on a Mac, this is a known issue, which is fixed in 8u40. You may need to use the ea version until the full release.
The basic history of this bug is that JavaFX implemented its own full screen implementation, in order to support OS X versions prior to 10.7 (which didn't have a native full-screen mode). That implementation uses an "exclusive mode", which prevents other windows from showing. This can get pretty bad: for example ComboBoxs won't work... The issue is fixed in 8u40 by using the native mode (since OS X versions prior to 10.7 are no longer supported anyway).
Note that if you don't programmatically set full screen mode, and allow the user to go to full screen using the Mac OS button on the window title bar, then the issue should not arise.

Related

Get control of an existing open window using Teststake White

For some reason, TestStake.White is not able to open an old windows application (which i can successfully run(win 7) by doubliclicking on the exe). I want to use an existing window to perform some action using White. I have no idea as to how to take control of an already opened window using White.
I tried to open the exe using batch command, but I still couldn't get any success. It shows me a yellow screen(app background) with no mouse control. Hence I want to launch the app manually and perform some automation actions on it.
If you know the text in the title bar of the window:
using TestStack.White;
public static class Demo
{
public static Window GetWindow(string windowTitle)
{
var window = Desktop.Instance.Windows().FirstOrDefault(x => x.Name == windowTitle);
}
}

Eclipse RAP multi-window/tab

I would like to have a multi-tab/windowed Eclipse RAP application.
I am able to open a second window using
UrlLauncher launcher = RWT.getClient().getService(UrlLauncher.class);
launcher.openURL("/gasf?foo=other_perspective");
Where I use the foo paramter to select the perspetive I want. However using this method will create a speparate http session, thus the various listeners and so on won't communicate with my first window.
I also tried opening a second window/page using
PlatformUI.getWorkbench().getActiveWorkbenchWindow().openPage("other_perspective" , null);
But this merely changes the current window perspective but does not open a second window or tab in my browser.
Has anyone achieved a multi-tab RAP application with working selectionlisteners between the tabs?
Thanks for any help you can provide
EDIT:
THANKS a lot ralfstx, as you pointed out, I can share the listeners or anything using the shared HTTP session, so far so good. Now the next step is to be able to update a tab based on an external event.
To try my idea of refresh from another tab, I did a dummy timer that does something 2 seconds later (i.e. simulate something triggered from another tab) with:
final ServerPushSession pushSession = new ServerPushSession();
pushSession.start();
Display display = Display.getDefault();
NavigationView navigationView = ((NavigationView) window.getActivePage().findView(NavigationView.ID));
timer.schedule(new TimerTask() {
#Override
public void run() {
display.asyncExec(new Runnable() {
public void run() {
navigationView.doSomething();
}
});
}
}, 2000);
This works! The pushSession.start() forces the UI to refresh without any user interaction. So now the action doSomething() is executed on the navigationView as soon as the 2 seconds are reached.
My only remaining concern is how much load this puts on the server, but its a reasonable solution at least. I validated your answer.
EDIT2:
Just to be complete, to make sure not bump in an invalid Thread access error since we are updating a display from another display, in the doSomething() method we must execute actions using display.asyncExec:
Display display = Display.getCurrent();
public void doSomething() {
display.asyncExec(new Runnable() {
public void run() {
treeViewer.refresh();
}
});
}
With the current architecture of RAP, you can't spread workbench windows over different browser tabs. Every new browser starts a new UISession which implies another Display (see Scopes in RAP).
However, the HttpSession should be the same (unless you have cookies turned off), so you could use this as a means of communicating between different browser tabs.

JavaFX: can you create a stage that doesn't show on the task bar and is undecorated?

I'm trying to create a stage that doesn't appear on the Windows task bar and is undecorated (no borders and no close/minimize/maximize buttons). My end goal is to create a tray icon application that will pop up notification windows.
It's similar to this question where I want the behavior of both StageStyle.UTILITY (which prevents the stage from showing on the task bar) and StageStyle.TRANSPARENT (which is a completely undecorated window).
The referenced question doesn't work for me because I don't have a parent stage from which to make a modal window. Any ideas on how to get this to work? Thanks
I was able to workaround this issue with the following code:
Stage stage = new Stage();
stage.initStyle(StageStyle.UTILITY);
stage.setMaxHeight(0);
stage.setMaxWidth(0);
stage.setX(Double.MAX_VALUE);
StageStyle.UTILITY will avoid creating a taskbar icon. I set the width and height to 0 make the window small and then use stage.setX(Double.MAX_VALUE) to place it far off screen so it doesn't show up. It's a bit hokey, but it seems to work fine.
JavaFX doesn't support the feature you request
You cannot do what you are asking (not show a task bar icon for an undecorated or transparent stage) using just the core Java 8 classes.
If you wish, file a feature request for this in the JavaFX issue tracker.
You could write some native JNI code and perhaps tell Windows not to display a task bar icon for your application. I do not know how you would do this.
Suggestion on task bar icons
I think it is fairly standard windowing toolkit behaviour to show the main application window in the task bar when the main application window is not hidden, so I suggest not trying to circumvent that standard behaviour.
Suggestion on notifications and tray icons
This isn't directly related to your question title, but is just comment on the end goal of your task - notifications for tray icons.
Most tray based applications I have seen don't have a task bar icon when the window associated with the tray icon is hidden, but do have a task bar icon when the window associated with the tray icon is displayed - so I suggest you stick with that setup.
Also, notifications are a standard part of the system tray icon infrastructure itself, so I suggest you use the standard mechanisms for system tray icon notifications, rather than using your own. This will also allow the user to configure whether the tray icon and it's notifications are shown using the standard OS tray icon and notification management UIs.
I created a sample application which uses the AWT SystemTray API to provide a System tray for a JavaFX application which uses some of the suggestions from this section. You can try it out if you like.
Full system tray support will come to JavaFX (probably with Java 9) when RT-17503 Provide system tray support is implemented.
This question is not really fresh, but I had the same problem and found no solution at first, but here is my workaround :)
The best solution I found was to set the primaryStage to style Utility and to make all childStages to Style Undecorated. Then set the opacity of the primaryStage to 0.0 so its not visible:
PrimaryStage:
primaryStage.initStyle(StageStyle.UTILITY);
primaryStage.setOpacity(0);
primaryStage.show();
Childs:
this.initOwner(owner);
this.initStyle(StageStyle.UNDECORATED);
Example code
public void start(Stage primaryStage) throws IOException{
//make primaryStage utility
primaryStage.initStyle(StageStyle.UTILITY);
primaryStage.setOpacity(0);
Stage secondaryStage = new Stage();
secondaryStage.initOwner(primaryStage);
//make secondaryStage transparent
secondaryStage.initStyle(StageStyle.TRANSPARENT);
//load ui via FXMLLoader
FXMLLoader loader = new FXMLLoader(getClass().getResource("/ui.fxml"));
AnchorPane pane = loader.load();//example with anchor pane
Scene scene = new Scene(pane,400,400); //example width and height
scene.setFill(Color.TRANSPARENT); //make scene transparent as well
secondaryStage.setScene(scene);
primaryStage.show();
secondaryStage.show();
}
Inspired by #Loki solution with a little upgrade (in my opinion)
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class TransparentAndUtilityStageApp extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
primaryStage.initStyle(StageStyle.UTILITY);
primaryStage.setOpacity(0.);
primaryStage.show();
Stage stage = new Stage();
Label label = new Label("Rainmeter");
StackPane stackPane = new StackPane(label);
stackPane.setPrefSize(600, 400);
stackPane.setStyle("-fx-background-color: transparent;");
Scene scene = new Scene(stackPane);
scene.setFill(null);
stage.initOwner(primaryStage);
stage.initStyle(StageStyle.TRANSPARENT);
stage.setScene(scene);
stage.show();
}
}
JavaFX DOES support that.
Don't put the main() method in your Application class. Just create another class to be your main class:
public class FxApplication extends Application {
}
public class Main {
public static void main(String[] args) {
PlatformImpl.setTaskbarApplication(false);
Application.launch(FxApplication.class, args);
}
}
As far as I know, JavaFX and Swing are interoperable and swing supports this feature. So if you can use Swing, integrate something like this into your application:
class MyFrame extends JFrame {
// ...
MyFrame() {
setUndecorated(true);
setType(Type.UTILITY);
}
// ...
}
I haven't tried this but other SO questions like this will probably help you on how to use Swing in JavaFX.

CrossUI.Droid.Dialog EntryElement loses focus with text prediction

I'm creating a new Dialog view in Droid platform, using the CrossUI.Droid.Dialog project. I'm also using bindings provided by the MvvmCross Framework.
Here is the code I have in the Droid view, to create and bind the Dialog:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
DroidResources.Initialise(typeof(Resource.Layout));
Root = new RootElement()
{
new Section("Private Configuration")
{
new EntryElement("Name:").Bind(this, "{'Value':{'Path':'Configuration.Name'}}"),
new EntryElement("Description:").Bind(this, "{'Value':{'Path':'Configuration.PrivateDescription'}}"),
new BooleanElement("Active?").Bind(this, "{'Value':{'Path':'Configuration.Active'}}")
},
new Section("Display Configuration")
{
new StringElement("Header Title")
{
Click = (o, e) => GoToHeaderTitleActivity(),
LayoutName = "dialog_rootNavigate"
}
}
};
}
When I run the app, the dialog is shown and the bindings are correct.
The problem I have is when I try to write something in one of the EntryElement, the focus just goes somewhere else... This only happens when I have 'Text Prediction' enabled.
I've checked the sample in Android.Dialog and all seems to work just fine.
I'm using a Galaxy Tab 2 7.0, with ICS 4.0
Does anyone had this problem?
Found the answer!!
Apparently there is a known issue in Android where EditText controls and ListView don't play nice. This is not a problem with MvvmCross or Monodroid.Dialog.
To overcome this (and I'm guessing this is the reason for it's existence?) use the MvxLinearDialogActivity when developing forms using dialog. The issue instantly disappears.
As the comment in the class says:
DialogActivity based on a linear view, this will solve all edittext related focus problems when using elements
suggestions at Focusable EditText inside ListView doesn't help for example

Refreshing the workbench

HI,
I am facing some problem.. I want to hide the menu when eclipse workbench starts.
But the problem is menu is not hiding when the eclipse workbench starts. It is hiding only
when some refresh is happened. for example: when I change the default perspective to some other perspective, I am getting the desired out put. That means menu is hiding.
But when the eclipse workbench is loaded it is not hiding the menu. Below is my code.
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
try {
IWorkbenchWindow window = Workbench.getInstance().getActiveWorkbenchWindow()
if(window instanceof WorkbenchWindow) {
MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
IContributionItem[] items = menuManager.getItems();
for(IContributionItem item:items){
System.out.println("item.getId()::: "+item.getId());
menuManager.remove("org.eclipse.ui.run");
menuManager.remove("help");
menuManager.remove("project");
}
}
}`
}
};
Given that you are looking to hide some features, I don't think that this is the best approach. (Not I am using the term feature here in the colloquial way, not as an Eclipse feature.
I would recommend one of two avenues:
Perspectives: See the extension point org.eclipse.ui.perspectives. This allows you to create a new perspective like the debug perspective or the Java perspective. Using a perspective, you can select exactly what menu items and views are shown and which ones are hidden.
Capabilities (aka activites): See the extension point org.eclipse.ui.activities. This allows you to have some fairly fine-grained control over what features are available in the workspace. See more info here: http://wiki.eclipse.org/Galileo_Capabilities
Put Your code in org.eclipse.ui.startup extention point. Make a Startup class after implementing the interface IStartup. For Details follow this link:-
Eclipse plugin : disable/enable dynamically an action from main menubar