The BeanTableModel is a concrete implementation of the RowTableModel introduced in a previous entry. It is used to display a bean in a row of a table. The model uses reflection to determine which properties of the bean should be displayed in the table.
Read the rest of this entry »
Bean Table Model
Posted by Rob Camick on November 27, 2008
Posted in Classes, Swing | 18 Comments »
List Table Model
Posted by Rob Camick on November 24, 2008
The ListTableModel is a concrete implementation of the RowTableModel introduced in a previous entry. It may provide a more flexible solution, than can be achieved by using the DefaultTableModel, because of the increased functionality inherited from the RowTableModel.
Read the rest of this entry »
Posted in Classes, Swing | 7 Comments »
Row Table Model
Posted by Rob Camick on November 21, 2008
The DefaultTableModel is a good general purpose model that allows great flexibility. It provides dynamic functionality when dealing with rows and columns. However, it has been my experience that most applications tend to deal with rows of data and dynamic rows more than column data and dynamic columns. So maybe if we remove the column functionality and improve the row functionality we can create a better general purpose table model.
Posted in Classes, Swing | 14 Comments »
Row Number Table
Posted by Rob Camick on November 18, 2008
Sometimes you may have a requirement for your table to look like a spreadsheet. That is you want column headings on the top and row numbers along the side. Well, a JTable has a default API to show a column header. It does this by adding the JTableHeader component to the column header area of a JScrollPane. Although there is no component in the API to display row numbers, the scroll pane also supports a row header area for a row header component. So all we need to do is create a row header component and the problem is solved.
Read the rest of this entry »
Posted in Classes, Swing | 57 Comments »
Component Tree Cell Renderer
Posted by Darryl Burke on November 16, 2008
A previous posting, Component Tree Model, showed how to reproduce the hierarchy of a GUI in a JTree. The default node rendering in a JTree is the String returned from invoking toString(). For reviewing the nesting of components in a GUI, a visual rendering is infinitely more useful and appealing.
ComponentTreeCellRenderer provides this functionality and, when used in conjunction with a ComponentTreeModel, provides all you need to analyze the layout of a GUI in minute detail.
Posted in Extensions, Swing | 4 Comments »
Component Tree Model
Posted by Darryl Burke on November 15, 2008
The code for a complex GUI can run into a few hundred lines. When maintaining someone else’s GUI code, or even your own code that you haven’t visited for some time, the ability to quickly identify the nesting of the various components can save much code-searching.
ComponentTreeModel attempts to address this need by reproducing the hierarchy of a GUI as a TreeModel.
Posted in Extensions, Swing | Leave a Comment »
Swing Utils
Posted by Darryl Burke on November 13, 2008
The standard SwingUtilities class has almost too many methods to count, including 4 that return various ancestors of a component. Alas, the only method of some use to obtain a descendant, getDeepestComponentAt(…) is useful only in the context of a MouseListener.
SwingUtils attempts to provide methods for obtaining a reference to nested components, together with some for obtaining the properties and UIDefaults pertaining to a component.
Posted in Classes, Swing | 2 Comments »
Left Dot Renderer
Posted by Rob Camick on November 12, 2008
The default renderer for a JTable uses a JLabel to provide the rendering. When the text on the label is truncated, the text is displayed left justified with trailing dots. There may be occasions when the trailing part of the text is more important than the start of the text and you would rather have the text right justified with leading dots. We can’t easily change the default behavour of a label, but we can change the behavour of the renderer.
Read the rest of this entry »
Posted in Classes, Swing | Leave a Comment »
Sorted Combo Box Model
Posted by Rob Camick on November 11, 2008
A JComboBox displays the items in the drop down list in the order in which the items where added to the combo box. If you want the items sorted then you can use the Collections.sort() or Arrays.sort() methods on the data before you create the combo box model. But what if you have a dynamic combo box and you want to keep the items in sorted order as new items are added?
Read the rest of this entry »
Posted in Extensions, Swing | 11 Comments »
Table Column Adjuster
Posted by Rob Camick on November 10, 2008
JTable sets a default width for each TableColumn in the table. When designing the table you can alter this width by setting the preferred size of the table column. However this size is only going to be a best guess as to the real width of the column. The real width of the column will never be known until data has been loaded in the table. It would be nice to be able to alter the width of the columns so that all text in the cell is displayed.
Posted in Classes, Swing | 88 Comments »