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
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.
How to increase the JScrollPane scrolling speed for mousewheel users
How to tell a Java JFrame to fill the entire screen
In an earlier tutorial, I shared some code on how to maximize a JFrame, but every once in a while you'll run into a situation where you want to fill an entire screen with a JFrame, but not call a method to actually maximize it. This is rare, but I just ran into this situation, so I thought I'd share the source code here.
Java screen size: How to determine the screen/display size
Java screen size FAQ - "How do I determine the size of the screen (or display) in pixels? (i.e., the screen size, or screen resolution)
The following Java code demonstrates how to get the screen size, using the Java Toolkit class:
Java EDT test: How to see if your code is running on the Java Event Dispatch Thread
Java Swing FAQ: How can I tell if my Java/Swing code is running on the Event Dispatch Thread (EDT)?
Java screenshots: How to take a screen capture with Java and Swing
I was just digging around through an old Java/Swing application and found this method that takes a snapshot of the current screen, and returns that screen shot as an BufferedImage, so I thought I would share it here.
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.
A Java program to open, read, and display an image file
In an earlier blog post I shared a small section of Java code that showed how to place an image on a JLabel.
How to create and use a JScrollPane in a Java Swing application
Summary: A simple Java JScrollPane source code example.
When you're first learning how to use Java Swing components, like a JScrollPane it can be a little hard to figure out how to get started. To that end I am trying to share several complete Java source code examples that demonstrate how to work with components like these.
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:
Java hyperlinks and the HyperLinkListener class
Using hypertext and hyperlinks in Java Swing applications makes them look more like web applications, and that's often a very good thing. Here's a quick example of how to add a Java HyperlinkListener to a component in Java. In this case the component I'm going to use is a JEditorPane.
A Java tooltip tutorial
Java Swing FAQ: How do I create a Java tooltip (also known as balloon or bubble help text)?
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.
A Mac OS X translucent JFrame with a dynamic slider control
Earlier today I wrote a blog entry about how to create a transparent/translucent JFrame on a Mac OS X system, and then I thought, "Wouldn't it be cool if you could dynamically control the transparency level of the frame?" I did a little bit of research to make sure this can be done, and sure enough, it can.
Java Swing Mac FAQ: How to determine if you're running on Mac OS X
Java Mac FAQ: How can I determine whether my Java/Swing application is running on Mac OS X, or some other operating system?
Here's the test I use to determine whether my Java application is running on Mac OS X: