Java: JOptionPane showMessageDialog examples (part 1)

I’ve been working with the Java JOptionPane showMessageDialog a lot lately, so I thought I’d create a page here with a number of showMessageDialog examples, sort of a JOptionPane reference page.

I’ll walk you through some JOptionPane examples here, starting with a simple example and then increasing the level of difficulty as I go on.

AppleScript dialog icons

AppleScript dialog icons FAQ: How do I put icons on my AppleScript dialogs?

I started to get into this a little bit in my earlier "How to customize AppleScript dialogs" tutorial, but in this article I thought I'd just dig into the AppleScript dialog icons details.

AppleScript dialog icons - The "with icon" syntax

In short, you add icons to your AppleScript dialog using the AppleScript "with icon" syntax. Here are a few simple examples.

First, the AppleScript dialog note icon:

How to fix the hide and seek problem with a Mac window and hidden dialog

Mac hidden window/dialog solution: One of the craziest things I see with the Mac OS X operating system from time to time is a game of "hide and seek" that you can get into with dialog windows in Mac applications. You'll hear people describe this problem something like this: "When I click on my Mac application window (like the main iTunes window), my Mac makes a 'dunk' noise (an error sound), like I'm doing something wrong by trying to click on the window.

A JOptionPane showOptionDialog example

The JOptionPane showOptionDialog is generally pretty straightforward, so without any introduction, here's the source code for a quick JOptionPane showOptionDialog example:

JOptionPane showInputDialog examples

I thought I'd share a collection of JOptionPane showInputDialog examples today. I'll start with the easiest example first, then try to add a little complexity as we go along.

First up, here's a simple JOptionPane showInputDialog example where I display a dialog that prompts a user to enter their name:

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.