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.
Archive for the ‘Classes’ Category
Combo Box Table Editor
Posted by Rob Camick on June 28, 2009
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.
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.
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.
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.
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.
Posted in Classes, Swing | 92 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?
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().
Posted in Classes, Swing | Leave a Comment »
Scrollbar Tooltip
Posted by Rob Camick on April 11, 2009
All Swing components support the usage of tooltips. If a tooltip is set for a given component then the tooltip will display when the mouse hovers over the component for a given period of time. Once the tooltip is displayed it may also be changed dynamically as the mouse moves over different areas of the component. Unfortunately this basic processing does not work for a JScrollBar. Typically a scrollbar will be dragged by the mouse, however the dragging action causes any tooltip that might be visible to be hidden (actually the mouse pressed causes the tooltip to be hidden). Therefore, a dynamic tooltip is not possible on a scrollbar.
Read the rest of this entry »
Posted in Classes, Swing | Leave a Comment »
Rotated Icon
Posted by Rob Camick on April 6, 2009
Icons are painted on a component in the orientation in which they where created. That is, the text in the TextIcon is painted in a left-to-right order. Image icons are painted as the image was created in the image editor. If we could change the orientation of the icon, then maybe we could create some interesting effects.
Posted in Classes, Swing | 10 Comments »