JDialog close/closing events

JDialog FAQ: How do I capture the JDialog close event?


To get the event when a JDialog is closed, you can add a window listener using addWindowListener to your JDialog, or add a component listener, using addComponentListener.

How to center a Java JDialog

Java/Swing FAQ: How do I center a JDialog?

Answer: The answer here really depends on what you mean by "center". If you really want to center a JDialog on screen, you can use code like this:

// center a jdialog on screen
JDialog d = new JDialog();
d.setSize(400, 300);

By calling setLocationRelativeTo with null, the JDialog will be centered.

Use Quaqua to display a sheet in a Java Swing application on Mac OS X (Part 2)


The running program

The Quaqua JSheet effect is very nice, it works as advertised. My only problem with it currently is that it does something to distort the image when the JSheet is displayed. You can see this problem in the image shown below, where the coffee cup image that sits on top of the caution image does not look very good:

Quaqua JSheet - Display a sheet in a Java Swing application on Mac OS X

I'm always looking for ways to make my Java Swing applications on Mac OS X look more and more like native Mac applications, and when a co-worker mentioned the name Quaqua, I decided to take a look at that library/framework one more time. I had looked at it before, but this time, looking at it with a new mindset, I noticed it offers a JSheet implementation.

JDialog focus: How to get input focus on a JDialog

I just solved a problem I was having in a Java Swing application getting input focus on a JDialog in a homemade text editor I use on my Mac OS X systems. Using my initial Java code the JDialog was properly getting input focus the first time it was displayed, but it was not properly getting input focus when it was displayed a second (or any subsequent) time.

JDialog icon - how to change the icon on a Java dialog (JDialog)

A couple of us were just working on a Java application that uses a JDialog, and were wondering how to change the icon image of a JDialog (a Java dialog).

Changing the JDialog icon image doesn't seem to be too hard, though it's not quite as simple as you might think. It turns out that the JDialog inherits the icon image from it's parent, which in my case is a JFrame. So in the code sample below I'm showing two different ways to do this.

Initial JDialog - JTable size

(From a recent email.) Help, I have a 13-column JTable, inside of a jscroll pane, inside of a borderlayout, inside a JDialog. Ideally, I would like the dialog to initially open up to the correct width needed to display the 13 columns without horizontal scrolling.

Setting the preferred width of each column (only) does not work very well. Setting the minWidth gets the columns to open up to the correct width, but then the last 7 or so columns fall off the right hand side of the dialog.