Back then, I made a post on how to create a simple custom popup dialog but the problem is that it is flat out boring.

There is no sense of depth that makes it appear 3D or something. Luckily, with CSS I was able to add a drop shadow effect behind the Stage window to make it look like the photo below.

popup

 

It looks better than without a shadow, right?

Here is the full CSS code.

The nice thing about Java FX is how CSS can easily be used to style the user interface. Making rounded corners on a window looks tedious when done programmatically.

However, with the use of CSS, this can easily be done.

Easy, right?

Well, there is no solution to making a Stage window modal when opened from a JFrame. At least not directly. I scoured through countless forums and blog posts but their solutions never made it modal.

A future version of Java FX may solve this problem. In the meantime, this is how I did it in Java FX 2. The same JDialog will be instantiated but set to invisible. I did this by calling the setUndecorated() method to true.

Within the JDialog class, that is where I called the Java FX code to open a Stage window dialog.

So now it is modal. But when you click the JFrame in the task bar in the Windows OS below, the Stage window is not sent to the front. This is not the behavior we want for a modal window, right?

What I did was to add a FocusListener in the JDialog custom class so that when it is in focus (since it is modal), it will call the Stage window object and send it to the front.

Here is the custom JDialog class I made. 

 
Then just call that from within your JFrame.

The StageModalDialog class is a custom class I made that inherits from the Stage class.

Related Posts Plugin for WordPress, Blogger...