Creating a new window on button click - Vaadin14 - java

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.

Related

How do I create a dialog window in Vaadin 8?

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.

Java GUI Design view not showing completely but code works

I am new to Java GUI I deigned and window and menu item using java design tool.But when I want to create window for menu item say New contact I did not find an option to do that in event handler so I did it manually by coding it.But when I go to design part and click on New Contact it does not show the window I created via code.
Here is the screen shot of deign view -when I click on New Contact nothing happens.
Now in the source code when I run it I get the window I coded
Is there any possible way I can make it work in design part? I did not find any option to do it in Add Event Handler
You do not want a JFrame to show another JFrame -- that's a bad GUI design since it means that your application is actually two applications. Better to show a dialog window such as a JDialog. Please see The Use of Multiple JFrames, Good/Bad Practice?
If you want to design a 2nd window, create a new Java program in NetBeans, one that creates this second window (again, better for it to be a JDialog, not a JPanel)
Give it a constructor that allows passing in the parent window, and then pass that to the JDialog super constructor
And then in your ActionListener code above, create a new object of this new program, passing in the current JFrame.
In the future, please post code as code-formatted text, not as an image, since this way we can copy, paste, compile and run it if we want, allowing us to better understand your code and your problem.

show hide panel in javafx using fxml

I have made the GUI of my javafx application in scenebuilder. I have correctly made the settings of placing the fxml and my application works perfect. Now I want to add action events to buttons and when a button is clicked, a panel should be shown and when other button is clicked, the other panel should be shown. Please help me. And remember that I am building my interface using scenebuilder i.e using fxml for my interface.
Thank you.
you can use the following code and hide the panes you want to hide
(paneid).setVisible(false);
and appear the new code
(paneid).setVisible(True);
here the id is the what you put for "fx:id" in scenebuilder.
What you can do is to write this code to hide the pane
(paneId).setVisible(false);
(paneId).setManaged(false);
and show it again by setting the parameters to true
(paneId).setVisible(true);
(paneId).setManaged(true);

Creating Internal Wizards using Java Swing

I want to create an internal wizard in my Java GUI application such that the clicking of a menu item results in popping up of a wizard that guides the user through a series of steps. I have done lot of research and couldn't find anything with decent enough documentation. Can someone help me out please? Has someone worked on creating a wizard that pops up INSIDE a GUI application?
Thanks in advance!
You can use cjwizard. It can be embedded inside a JDialog as it is based in JPanel.
And you can see how to use it in https://github.com/cjwizard/cjwizard/blob/master/docs/quickstart.md for example:
// create the WizardContainer:
final PageFactory pageFactory = /* create a PageFactory, see the link */;
final WizardContainer wizard = new WizardContainer(pageFactory)
// stick the WizardContainer into a dialog:
final JDialog dialog = new JDialog();
dialog.getContentPane().add(wizard);
dialog.pack();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
Disclaimer: I'm part of the development team.
If there are no third-party libraries to satisfy the requirements you have then you can just write your own approach. A set of panels, each one having Previous, Next buttons and some of them Finish. The current panel just needs to know which are the previous and the next panels.

modal parentless JDialog does not grab focus

We have an application which, as its first UI action, displays a modal JDialog without a parent frame.
public LoginDialog(Frame owner, Config config, Object... params) {
super((Frame)null, true);
It unfortunately has the annoying characteristic that when it appears, although it comes to the front, it does not grab the focus.
So the user, after launching the application by double-clicking on the start menu, has to use the mouse to select the "login" dialog and type in information.
Is there a way to make this JDialog grab the focus when it appears in the front?
I've tried calls to "requestFocus" before, after and via invokeLater "during" the call to setVisible(true) - but none of these seems to have any effect.
How do we make a modal dialog grab the focus?
UPDATE: The issue was the code used to try to present a background "wait window". This window was displayed "behind" the login dialog as a hack so that when the dialog disappeared the user would see the "Please wait" message. As it was the first window created by the application, it got the focus. I am not sure if there would have been a way to make the dialog gain the focus again inside the event dispatch thread with this hack - but I fixed it by un-hacking it and doing things properly.
First, it a little strange that modal dialog is parent-less. The point in modal dialog is that it is displayed on its parent and does not allow to access parent.
So, the first recommendation is to make it non-modal. I believe it will work.
BTW I have just tried to create such dialog and have not problems with focus. Try probably to simplify your code:
JDialog d = new JDialog();
d.setSize(200, 200);
d.setVisible(true);
This works for me and I believe will work for you. Now start changing this simple code towords your real application code. At some point it will stop working and you will see where the problem is.
If nothing helps try to use the trick I described in this article. Look for title "Portable window activation". I hope it will help.
See Dialog Focus for a potential fix using a RequestFocusListener. I have used it successfully for setting focus in JOptionPane dialogs.
1) you have to create JDialog contents and showing container wrapped inside invokeLater()
or best and safiest way is
2) you have to set for ModalityTypes or Modal for parent
3) only one from containers could be Modal in applications lifecycle

Categories

Resources