We are using Vaadin 8 and, unfortunately, we're stuck with that version for a while.
I need to be able to create a dialog window when the user clicks a button. This window doesn't have to be draggable but it needs to be customizable (i.e., different sizes with different components inside). For example, the window would have textfields, labels, combos, etc.
All of my searching is recommending I use Vaadin 11 or higher. We cannot do that at the moment.
Is there an example of how I can do this in Vaadin 8? We do have the paid, pro license if that helps.
I have a crude version working with the PopupView:
DateProcessedFilterUi dateProcessedFilterUi = new DateProcessedFilterUi();
PopupView dateProcessedPopupView = new PopupView("", dateProcessedFilterUi.getPopupComponent());
Button dateProcessedButton = new Button("Past Hour", click -> dateProcessedPopupView.setPopupVisible(true));
dateProcessedPopupView.addPopupVisibilityListener(event -> dateProcessedFilterUi.setVisible(event.isPopupVisible()));
This works but the popup appears over the button and disappears when my mouse leaves it. If I could at least stop the auto-closing of the window then that would help.
Thanks for any suggestions.
You are looking for the Window class (com.vaadin.ui.Window).
Vaadin Docs for Window
Window Demo
In Vaadin Flow (10+), it is replaced by Dialog.
Related
I want to create a new Window using:
final Window window = new Window("Window");
this.getUI().addWindow(window);
This is from the Vaadin homepage https://demo.vaadin.com/sampler/#ui/structure/window
But unfortunately my IDE is showing the following error:
The constructor Window(String) is undefined.
When i delete the string, it says: the constructor Window() is not visible.
Why is that? In the vaadin demo it works just fine.
There is no Window class in Vaadin 14.
The demo page you linked in the question is about Vaadin 8.
In Vaadin Flow (Vaadin 10+), the Dialog is used instead of the old Window. It's not exactly the same as the old Window - for example the Dialog has no maximize or close button automatically. But along with other components you want to show within that Dialog, you can add for example a button that will close the dialog when clicked. Or let the dialog close when the user clicks outside it using dialog.closeOnOutsideClick(true);
Edit: go check out this vaadin blog post of a good looking Dialog example, with video (and code is also linked there): https://vaadin.com/blog/new-component-features-and-development-time-improvements-in-vaadin-14
The Window class is part of the Vaadin-Framework. It doesn't exist like that in rapidclipse and other IDE's. You have to write your own Window class (by extending Panel) or you can copy the Window class from their github.
refer to:
https://github.com/vaadin/framework/blob/master/server/src/main/java/com/vaadin/ui/Window.java
You are getting this error, because you are trying to access the Window class of the rapidclipse framework, which apparently has no constructor and is meant for something else.
I am trying to implement a simple logic in my application where the user is shown a popup (after sometime of application launch). The popup simply shows a TextView with some info message. This message is refreshed every time the application is launched and a new message is shown.
The UI of the popup matches my application UI - here maybe just popup background images is needed. Also one close button (X) is shown at the top right corner of the popup - to close this popup.
Logic of Showing Message: I have a String array having some 100 strings stored in it. I randomly pick one string from this array and populate the popup TextView showing the message. Please suggest if there is any better approach than what I am doing already here. Also is it possible to logic that if one message is picked then the same message is not picked until the other messages are shown at least once?
Logic of Showing Popup: This is what I am not able to implement. I do not want to anchor the popup with any user Event or Button click. I simply wants to show the message after some time - say
Thread.sleep(3000);
Now I have tried to use PopupWindow for this using the below code.
PopupWindow infoPopup;
LinearLayout infoLayout;
TextView infoTextView;
Button infoButton;
infoTextView = new TextView(this);
infoTextView.setText("Testing Popup Text");
infoTextView.setPadding(10,10,10,10);
infoButton = new Button(this);
infoButton.setText("Close");
infoLayout = new LinearLayout(this);
infoLayout.setOrientation(LinearLayout.VERTICAL);
infoLayout.addView(infoTextView);
infoLayout.addView(infoButton);
infoPopup = new PopupWindow(infoLayout,LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
infoPopup.setContentView(infoLayout);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
infoPopup.showAtLocation((CoordinatorLayout)findViewById(R.id.main_content),Gravity.CENTER,100,100);
But this popup is showing error at the last line giving null pointer on my
(CoordinatorLayout)findViewById(R.id.main_content)
parameter.
The issue that I am getting are:
First of all, I am not sure if this is the right approach of showing a custom UI popup. I am aware of AlertDialog but not sure which is the best option to go in this case - Please suggest.
Why the CoordinatorLayout is showing null pointer?
How to implement the top right (X) button logic in this Popup ?
1. Yes there are so many options for showing a custom UI popup in Android. You might select one from PopupWindow, AlertDialog or Dialog Activity. You need to decide which suits you best.
If you need to customize your UI a lot and have to show a list or some complex GUI then I would suggest you launch an Activity with theme.Dialog. Just set the theme of the Activity to something like this android:theme="#android:style/Theme.Holo.Light.Dialog". There's a plenty of tutorials for implementing a dialog Activity.
PopupWindow is another tool to customize your custom pop up anywhere in the screen. If you're showing this popup always in the middle of the screen, then I would like to suggest not to use this. The AlertDialog should work fine.
AlertDialog has many variants and as far as I can assume your problem, this one suits you best. You can have a cross button too in the top-right corner of the dialog (You can set the icons anywhere, as you can provide a custom layout to an AlertDialog). Personally I use this library to provide a custom layout to my AlertDialog. You can have a look at this too.
2. The NullPointerException is simple. Your layout doesn't have any id named main_content. Post your logcat if this doesn't solve your problem. Post the layout too.
3. As I've told you earlier, I use the library to provide a custom layout to an AlertDialog and you can have a look at it too. So after implementing this library you can easily design your own layout with a cross button and implement the onClick functionalities easily.
Hope this helps.
Activity with theme Dialog.
This is not a good idea. It looks like a pop-up, but you can't click outside the pop-up to close it.
PopupWindow
It will stop the application. When the user finish clicking the pop-up, the application can work again.
AlertDialog
The best one, it will not stop the application and can be closed by clicking outside the dialog.
I'm trying to make an overlay on the screen using JavaFX and an issue I'm having is that whenever my overlay pops up, it steals focus from whichever program I'm currently in. The issue with this is that my overlay allows the user to simulate keyboard key presses using the robot class (like an on-screen keyboard) and without keeping the focus in the original window, the typed characters have nowhere to go. I've tried setting the modality to none, but that's also the default option and it doesn't seem to be doing anything. Would putting my JavaFX scene in a JFrame work or is there some better way to do it only in JavaFX?
Try this
when focused -> compute what you want to
then call Stage.toBack(); //the currently focused window prior to yours will gain focus back
I am trying to use a JDialog at the right of the screen, everything is almost perfect, but, if someone press the button on ther right end of the TaskBar, click on "Show Desktop area" my JDialog disappears I have to use ALT + TAB to get it back in in front. I can't set it AlwaysOnTop because I use other 3rd party programs that are fullscreen.
I tried:
jdigCentral.setAutoRequestFocus(true);
jdigCentral.setAlwaysOnTop(true);
and others, but without success
How can I have my JDialog to stay over just the Desktop Area?
Is jdigCentral your dialog box? If so then try this:
jdigCentral.setModal(true);
That will keep the dialog box on top of the parent JFrame. But I'm confused about the use of the word Desktop Area. Do you mean you want to keep the dialog box on top of the parent frame, or do you want it to always show on top of all other programs running on your desktop?
Can anyone kindly help me out?
I want to create an app, like user access control(UAC) application. When UAC is running we cannot click anywhere on the screen, unless we close UAC window. Also we cannot press any key to do anything, like window key or any of the function key. So I want to create a similar application using C ++ code to control keyboard and mouse, that only mouse and keyboard is enabled in my application window and disable outside and unless i do not close my app i cant perform any other task. My application would be just a graphical simple window with a close button, and obove mentioned controls.
A long time ago Windows supported system modal dialogs. These would prevent the user from interacting with other windows including the desktop. Microsoft removed support for this a long time ago due to the problems that it caused.
Now when Windows needs to provide a system modal window for UAC they use a bit of desktop magic. To simulate a system modal window UAC does something like this.
Create a bitmap and take a snapshot of the current desktop.
Darken the bitmap
Create a new desktop
Set the new desktop as the currently active one.
Create a window the size of the new desktop and draw the bitmap in it.
Now they have a desktop that looks like the old and acts as if it were a system model window. You are then free to create a child window to grab input from the user. The example below shows how to create a desktop and switch to it and should be a good starting point for what you want to do
// TODO: Make a copy of the current desktop
// Prepeare a new desktop and activate it
HDESK oldDesktop = GetThreadDesktop(GetCurrentThreadId());
HDESK desktop = CreateDesktop(L"MyDesktop", NULL, NULL, 0, GENERIC_ALL, NULL);
SwitchDesktop(desktop);
// TODO: Create the window that draws the snapshot of the old desktop
// TODO: Create a dialog with buttons and stuff
// Since we don't have a window sit for 5 seconds staring at blank screen
Sleep(5000);
// Switch back to the old desktop and destroy the one we created
// ALERT: If we crash or exit without doing this you will need to
// restart windows
SwitchDesktop(oldDesktop);
CloseDesktop(desktop);
You can find more information on the desktop related API's