jfc-swing

recent posts related to swing and java gui development

Transparent JFrame - How to make a JFrame transparent on Mac OS X alvin May 12, 2011 - 11:05pm

Summary: How to make a Java JFrame transparent (translucent) on Mac OS X.

A lot of people complain about a lot of things in regards to Java on Apple's Mac OS X platform, and okay, occasionally I'm one of them, but a very cool thing you can do on OS X is to create translucent (transparent) frames and windows with Java.

Java, Mac, and the Dock: How to handle drop events to a Mac OS X Dock icon

Lately I've been doing a lot of Java programming on Apple's Mac OS X platform, and my most recent effort has been to handle drag and drop events in my Java Swing application. Not satisfied to handle "simple" drag and drop events, I decided I wanted to take my application even farther, and let users drag files and images to my Java application icon in the Mac Dock.

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

A Java tooltip tutorial alvin November 10, 2009 - 10:57am

Java Swing FAQ: How do I create a Java tooltip (also known as balloon or bubble help text)?

Java JButton and button group example alvin November 5, 2009 - 9:44pm

Here's a very simple Java JButton example that shows how to create and use a button group in Java using the ButtonGroup class. With this code, when the user selects one JButton in the group of buttons, the other JButton's will be de-selected.

How to center a JFrame on screen

I'm often asked, "How do I center a JFrame on screen?", or, "Is there a method to center a JFrame?"

I always center my initial JFrame on screen using the setLocationRelativeTo method, and pass it a null reference. As the Javadoc for setLocationRelativeTo method states:

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

JButton example - how to create a JButton rollover effect

Problem

You want to implement a nice mouse rollover effect on the buttons (JButton instances) in your Java Swing application. This Java button rollover effect makes your application feel more "alive" and interactive.

You can see what this button rollover effect looks like in the following two images. First, here's what a Java button (JButton) looks like normally:

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

Java - get the number of mouse buttons alvin July 14, 2009 - 12:26pm

Java mouse buttons FAQ: How do I determine the number of mouse buttons in a Java application?

I'm working on a Java Swing application, and I'd like to be able to determine the number of mouse buttons on the current system (Mac, Linux, Windows).

A JButton tooltip example alvin July 13, 2009 - 5:40pm

Java/Swing FAQ: How do I set the help text (i.e., help text, balloon text, tooltip text) on a JButton?

Just call the setToolTipText method on the JButton. Here's a quick JButton tooltip display example:

// create a button with tooltip help text
JButton button = new JButton("Click Me");
button.setToolTipText("Click this button to make something happen.");
JTextField tooltip display - how to set a balloon tooltip on a JTextField alvin July 13, 2009 - 5:38pm

Java/Swing FAQ: How do I set the help text (i.e., help text, balloon text, tooltip text) on a JTextField?

Solution: Just call the setToolTipText method on the JTextField. Here's a quick JTextField tooltip display example:

// create a textfield with tooltip help text
JTextField textfield = new JTextField(10);
textfield.setToolTipText("Enter your username over here, that other thing is a label.");