Posted by Darryl Burke on December 29, 2008
Thanks for the various comments. We’ll try to keep you updated here when changes are made to the code so you can get a new copy.
If you are interested in receiving an RRS feed whenever this posting is updated click on the “Read the rest of this entry” link below for more information on how to do this.
- added support for multiple fonts and font sizes. That is the line height of the line number will now vary to match the related text component.
- attribute changes are only compounded when the caret position hasn’t changed. This indicates a change in attribute as a result of syntax highlighting. Other attribute changes like “bolding” text will involve a caret change as the text is selected and will be considered a separate edit for undo purposes
- also added a Webstart demo to show the above behaviour
Read the rest of this entry »
Posted in Uncategorized | 6 Comments »
Posted by Rob Camick on July 12, 2009
A JTable is used to disply rows of data. There may be times when you want to do some processing on a row of data. Maybe you want to display a popup form with more details or maybe you simply want to delete a row. In these cases it may be desireable to add a button to one of the table columns so you can invoke this processing. The problem is that JTable doesn’t support a button renderer or editor.
Read the rest of this entry »
Posted in Classes, Swing | 5 Comments »
Posted by Rob Camick on July 5, 2009
The Color class in Java uses Red, Green and Blue (RGB) values to specify a Color. I don’t know about you, but I have no idea how to manipulate a given Color to return a related Color. For example, how would you go about returning a darker or lighter Color? Sure the Color API supports brighter() and darker() methods, but they don’t seem to work that well and you can’t control the degree of brightness or darkness. The API also supports a HSB (Hue, Saturation, Brightness) color space which seemed promising, but didn’t quite return the results I was looking for.
Read the rest of this entry »
Posted in Awt, Classes | Leave a Comment »
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 | Leave a Comment »
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 | Leave a Comment »
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 | Leave a Comment »
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 | Leave a Comment »
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 | Leave a Comment »
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 | 13 Comments »
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 | Leave a Comment »
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. 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 | 2 Comments »