Posts in the “jfc-swing” category

Java clipboard example: How to write text to the system clipboard

I was just digging around through one of my Java Swing applications, and I found this method that writes a given String to the system clipboard, using the Toolkit, Clipboard, and

How to increase the JScrollPane scrolling speed for mousewheel users

Java Swing FAQ: How do I increase the JScrollPane scrolling speed when using the mouse wheel?

Once you put a component (JTextArea, JEditorPane, JTable) into a JScrollPane in a Java Swing application, you'll quickly see that the default scrolling speed when trying to vertically scroll the viewport with the mousewheel is very slow. To make your scroll pane faster, i.e., more like a native Mac or Windows application, you'll want to increase this default mousewheel vertical scrolling speed.

Mac specific properties for Swing applications

I think I've mentioned parts of this in other blog entries, but as I was just digging through a Java Swing application that I wrote specifically for the Mac OS X platform, I ran across the following source code, which sets up all of my system properties for the Mac environment:

Java animated GIF example

Someone asked yesterday if you can use animated GIF images in Java applications using the JFC/Swing toolkit. That's something I hadn't tried with Java and Swing before, so I wrote a quick test program, and sure enough they work.

I just load an animated GIF as an ImageIcon, then put it on a JLabel and display it on a JFrame, and the animation starts right up. Note that I'm using a Java/JDK 1.4.x release.

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:

How to add stylesheet information to a JEditorPane

Did you know that you can use CSS styles when displaying HTML in a Java Swing application? It's pretty cool, and it can help spice up any simple HTML you may currently be showing in a Java-based editor or viewer. In this tutorial I'll share some source code that shows how this works.