Java Tips Weblog

  • Blog Stats

    • 2,613,979 hits
  • Categories

  • Archives

Combo Box Table Editor

Posted by Rob Camick on June 28, 2009

When using a JComboBox as an editor in a column of a JTable the same combo box is used for all rows in the column. There may be times when you want different rows to use a different combo box.

Read the rest of this entry »

Posted in Classes, Swing | 4 Comments »

Animated Icon

Posted by Rob Camick on June 21, 2009

I’m sure everybody has seen or used animated gifs on a webpage. As far as I know an animated gif is created using an image editor and the images and animation information is contained within a single gif file. Have you ever thought about dynamically creating an animated gif? Well, I don’t know how to do that, but I might have an approach that will work just as well.

Read the rest of this entry »

Posted in Classes, Swing | 4 Comments »

Moving Windows

Posted by Rob Camick on June 14, 2009

Over the years I’ve seen many questions asking about borderless windows. The common suggestion is to use a JWindow or an undecorated JFrame, depending on the requirements. Often you will then find a follow up question asking how to move the window now that there is no title bar. The common answer is that you need to add your own listeners to handle the dragging of the window.

Read the rest of this entry »

Posted in Awt, Classes | 51 Comments »

Table Cell Listener

Posted by Rob Camick on June 7, 2009

A TableModelListener is used to listen for changes to a TableModel. Relying solely on the TableModelListener can have potential drawbacks. In particular:

  • in some cases, a TableModelEvent is fired even though nothing has changed. This would happen when you place a table cell in editing mode but then simply tab (or click) off the cell without changing anything.
  • in all cases, when the event is received you only have access to the current state of the TableModel. This means that you know what has changed, but you don’t know what it was changed from.
Read the rest of this entry »

Posted in Classes, Swing | 81 Comments »

Backgrounds With Transparency

Posted by Rob Camick on May 31, 2009

Swing components allow you to change the background color of a component simply by using the setBackground() method. It is also possible to use a Color created with an “alpha” value. The alpha value defines the transparency of a Color. Unfortunately, once you start using alpha values in your background color you may encounter some undesireable painting artifacts.

Read the rest of this entry »

Posted in Classes, Swing, Tips | 27 Comments »

Text Component Line Number

Posted by Rob Camick on May 23, 2009

Over the years I’ve seen many requests in the forums for the ability to display line numbers in a text component. I’ve probably seen just as many solutions as well. I even posted my own solution years ago. It was my first attempt at doing custom painting so I figured now was a good time to revisit that code to see if I could improve on it.

Read the rest of this entry »

Posted in Classes, Swing | 92 Comments »

Combo Box No Action

Posted by Rob Camick on May 17, 2009

A common GUI design principle is that the user should be able to use the keyboard or the mouse to achieve the same functionality. Because of this principle I’ve alway been a little puzzled about the default behaviour of a JComboBox. In particular the behaviour is different when using the mouse versus the keyboard when the popup is visible.
Read the rest of this entry »

Posted in Swing, Tips | 3 Comments »

Custom Painting Approaches

Posted by Rob Camick on May 8, 2009

The basics of custom painting are explained in the section from the Swing tutorial on Custom Painting (see link below). The main idea is that you can customize a component by overriding its paintComponent() method. Typically, JComponent or JPanel will be overridden to do custom painting. A concern of many people is adding too much painting code to the paintComponent method which might result in excessive CPU usage or slow painting. Is this a valid concern and if so, then is there anything that can be done to minimize these problems?
Read the rest of this entry »

Posted in Swing, Tips | 7 Comments »

Closing an Application

Posted by Rob Camick on May 1, 2009

I’m sure the users are having a great time using your application but as we all know, “all good things must come to an end“, so at some time the user is going to close the application. The user will generally have three ways to close an application:

  • click on the “Close” button of the frame
  • select the “Close” item from the sytem menu
  • select the “Exit” item that is typically found in the “File” menu of the application

You may have some application specific “close processing” such as:

  • prompting the user to confirm closing of the application
  • saving application properties to be used the next time the application starts

So how do you ensure that close processing is done no matter how the application is closed?

Read the rest of this entry »

Posted in Classes, Swing | 18 Comments »

Jump Scrollbar Tooltip

Posted by Darryl Burke on April 22, 2009

Since a JumpScrollBarModel’s functionality relies on not returning the current value while adjusting, a ScrollBarToolTip cannot correctly reflect the position of the scroll thumb.  JumpScrollBarToolTip extends ScrollBarToolTip and overrides the method getToolTipText(…) to utilize the value returned by the model’s getTrueValue() instead of getValue().

Read the rest of this entry »

Posted in Classes, Swing | Leave a Comment »

 
Design a site like this with WordPress.com
Get started