Technical Information Database
FAQ: TI4690J - dbSwing FAQ
Category: JDBC/ODBC
Platform: All Windows
Product: All
dbSwing Faq
dbSwing FAQ
Administrivia
DW000: What is this FAQ about?
DW001: When was this FAQ last updated?
DW002: Where can I send comments or suggestions?
Swing and dbSwing
DW100: What is dbSwing?
DW101: What else does dbSwing add to Swing?
DW102: Can dbSwing only be used with DataExpress
DataSets?
DW103: What are the advantages of using dbSwing
in a DataExpress application?
DW104: Where can I get dbSwing source code and
classes?
DW105: Where can I find information on Swing?
DW106: Where can I find more information on
dbSwing?
dbSwing and JBCL
DW150: Why two sets of components, dbSwing and
JBCL?
DW151: What can dbSwing do that JBCL can't do?
DW152: What can JBCL do that dbSwing can't do?
DW153: I'm used to JBCL. How do
I figure out which dbSwing component to use?
Data awareness,
models, and binders
DW200: What's the difference between a model
and a binder?
DW201: What models and binders does dbSwing
provide?
DW202: Why isn't there a model and a binder
corresponding to each visual component?
DW203: When should I use a dbSwing model or
binder? When should I not use one?
DW204: How do I use a dbSwing model with my
non-dbSwing visual component?
DW205: How do I use a dbSwing binder with my
non-dbSwing visual component?
DW206: What are the JdbNav components all about?
DW207: Why don't I see data in a component that's
connected to a dataset by a dbSwing binder?
DW208: Why don't I see data in a component that's
connected to a dataset by a dbSwing model?
Scrolling
DW250: Why doesn't my JdbTable, JdbList, etc.
scroll?
DW251: What are the advantages of using TableScrollPane
instead of JScrollPane?
Displaying and
editing data
DW300: Why are my edit masks ignored?
DW301: How do I display an image?
JdbTable
DW350: How do I display a picklist of choices
in a column of a JdbTable?
DW351: I don't want to display all the columns
of my dataset in my JdbTable. How do I hide columns?
DW352: How do I set properties on a column of
a JdbTable?
DW353: How do I change the default order of
columns in a JdbTable?
DW354: How do the setHiddenColumns() and setCustomizedColumns()
methods interact?
DW355: I'm having trouble with focus and editing
in a JdbTable. What's happening?
DW356: How do I set intercell spacing (the margins
between grid lines and data)?
Text components
DW400: How can I make a JdbTextField display
a drop-down picklist?
DW401: How do I limit the number of characters
entered in a JdbTextField?
Tree components
DW450: Why can't I fill a JdbTree with data from
a dataset by setting properties?
DW451: How do I fill a JdbTree with data?
List and combo
box components
DW500: How do I fill a JdbList or a JdbComboBox's
drop-down with values?
DW501: How do I define a dataset Column's picklist
property?
DW502: How do I display multiple columns in
a JdbComboBox's drop-down?
DW503: How do I control the width of a JdbComboBox's
drop-down?
Button components
DW550: How do I group radio buttons so only one
of them can be selected at any time?
DW551: How do I force all buttons in the group
to be unselected when a new row is inserted?
General runtime topics
DW600: What JDKs can I use with dbSwing?
DW601: Contextual (popup) menus don't seem to
work very well.
Administrivia
DW000: What is this FAQ about?
This FAQ answers common questions about dbSwing, JBuilder's set of Swing-based
components. This document assumes that you are using dbSwing from
JBuilder 3.0 or a later version.
DW001: When was this FAQ last updated?
August 25, 1999.
DW002: Where can I send comments and suggestions?
Please send comments and suggestions to dbswingfaq@inprise.com.
We welcome comments about
-
The organization of this FAQ.
-
The clarity and correctness of questions and answers.
-
Our assumptions about who will read this FAQ, what they know about JBuilder
and dbSwing, and what they want to learn.
-
Material that should be added. We especially welcome this if you
include the answers for any questions you suggest adding!
If you have a question about dbSwing, please do not send it to this email
address. Instead, post it on the newsgroup so other newsgroup readers
can help answer it or benefit from the answer.
Swing and dbSwing
DW100: What is dbSwing?
dbSwing is a package of Swing-based components specifically designed
for building database applications with JBuilder's DataExpress. Most dbSwing
components extend Swing components. dbSwing includes data-aware button,
field, table, tree, list, and combo box components, among others. If you
know Swing, you already know a lot about dbSwing. If you don't know
Swing, you'll learn about its organization and API by using dbSwing.
A data-aware component usually has a dataSet property and a columnName
property. When you set these properties, the component displays data
from the current row of the dataset it's bound to. When you change
the value in the component (by checking a check box, selecting a different
value in a list, etc.) the new value is written to the dataset. dbSwing
also includes "Nav" components,
which synchronize with a dataset by navigating it instead of writing to
it. dbSwing's built-in support for DataExpress makes it much easier
to develop applications that manage data.
DW101: What else does dbSwing add to Swing?
dbSwing has other advantages over Swing: performance, especially
in table, list, and combo boxes, is better; added properties make working
in the JBuilder designer easier; text fields and tables have popup menus;
tables support multi-column headers; and a few Swing bugs are fixed in
dbSwing. In addition, dbSwing contains helpful utility components
and non-data-aware visual components:
-
FontChooser: allows the user to select a font from local fonts supported
by Java 2
-
RepeatButton: fires repeated ActionEvents when held down
-
TableScrollPane: improves scrolling for tables and other components
-
Intl menu components: improve handling of mnemonics in menu components
-
IntlSwingSupport: automatically localizes several Swing dialogs
DW102: Can dbSwing only be used with DataExpress
datasets?
No. Some data-aware components have improvements over the corresponding
Swing components that make them useful even if you don't use DataExpress.
For example, JdbTable has default row and column headers and better data
validation support. And dbSwing's utility and non-data-aware component
are useful whether you use DataExpress or not.
DW103: What are the advantages of using dbSwing
in a DataExpress application?
dbSwing contains these utility components to aid application development
with DataExpress:
-
DBDisposeMonitor: closes data stores; allows closed datasets to be
garbage collected
-
DBExceptionHandler: displays an error dialog box when a DataSetException
is generated
-
DBEventMonitor: reports the events fired by one or more datasets
-
DBPasswordPrompter: prompts for a password and opens a connection to a
database
DW104: Where can I get dbSwing source code
and classes?
dbSwing source code and classes are included in the Professional and
Enterprise versions of JBuilder.
DW105: Where can I find information on Swing?
Source code for Swing and other JDK packages is included with JBuilder.
To view the JavaDoc documentation built from this source, select Help |
Java Reference. To view the source code for a class, place the editor's
text cursor on a Swing class name or instance, right-click, and choose
Browse Symbol At Cursor. For announcements, newsletters, tutorials,
bug reports, and other information, search for "Swing" on the JavaSoft
web site at www.javasoft.com or the Sun site at developer.java.sun.com.
Third-party books on Swing are also available.
DW106: Where can I find more information on
dbSwing?
-
Package reference for com.borland.dbswing: select Help | dbSwing
Reference.
-
Reference for a dbSwing class: place the editor's text cursor
on a dbSwing class name or instance, right-click, choose Browse Symbol
At Cursor, click the Doc tab.
-
Late-breaking notes: read the dbSwing section of HintsAndTips.txt
in your JBuilder3 directory.
-
Sample applications: JBuilder3samplescomborlandsamplesdbswing.
-
Newsgroup: follow the link at www.borland.com/newsgroups/#jbuilder
to news://forms.inprise.com/borland.public.jbuilder.dbswing.
dbSwing and JBCL
DW150: Why two sets of components, dbSwing
and JBCL?
JBCL was developed before Swing existed and is a complete, mature set
of components. Swing is newer but, because it has Sun behind it,
has become the industry standard. Swing also has better cross-platform
look-and-feel support. dbSwing's extensions to Swing make it easy
to work with dataset data while leveraging the benefits of Swing.
If JBCL and Swing/dbSwing both provide the features you need, you
should choose Swing/dbSwing because it is more of a standard.
DW151: What can dbSwing do that JBCL can't
do?
-
Better look-and-feel support.
-
Text components handle rich text and HTML.
-
JdbNavToolBar - dbSwing's navigation component - has repeat buttons, lets
you remove or disable buttons easily, and supports vertical placement.
-
dbSwing includes data-aware toggle button and slider components.
-
JdbTable offers multi-line column headers and hidden columns.
-
dbSwing's combo box is editable.
-
The navigation and status components can be set to automatically bind to
the data component with focus. This makes it easy for master and
detail datasets to share a navigation component, for example.
-
dbSwing's utility components help you work with events, exceptions, and
datastores.
DW152: What can JBCL do that dbSwing can't
do?
-
dbSwing does not support edit masks. A column's display mask (either
user-specified or default) guides parsing and formatting. You cannot control
input character by character.
-
There is no combo box cell editor for JdbTable.
-
JBCL runs on older JDKs. dbSwing requires Java 2's JDK 1.2 or a newer
JDK.
-
dbSwing has nothing comparable to JBCL's TransparentImage and ShapeControl
components.
DW153: I'm used to JBCL. How do I figure
out which dbSwing component to use?
The "dbSwing, Swing, and JBCL: Which do I use?" section of the documentation
for the com.borland.dbswing package has a table showing the mapping between
dbSwing and JBCL components.
Data
awareness, models, and binders
DW200: What's the difference between a model
and a binder?
Models and binders both connect a component to a dataset, often to a
specific column of the dataset. We call these components "data-aware".
A model fills a component with data from a dataset. A binder synchronizes
the component and the dataset. Usually, "synchronizes" means two
things:
-
When the dataset is navigated, the value displayed in the component changes.
-
When the user edits the value in the component, the dataset is updated.
"Nav" components respond
differently to user manipulation: they synchronize with the dataset
by navigating the dataset to a row with a data value that matches the value
in the component.
DW201: What models and binders does dbSwing
provide?
-
DBButtonDataBinder
-
DBLabelDataBinder
-
DBTextDataBinder
-
DBSliderDataBinder
-
DBListModel, DBListDataBinder
-
DBTableModel
-
DBTreeDataBinder, DBTreeNavBinder
DW202: Why isn't there a model and a binder
corresponding to each visual component?
Models and binders aren't quite as systematic as wed like. There
are necessary differences depending what type of component a model or binder
works with:
-
A button, label, or text component works with just one data value at a
time, so it doesn't need the power and complexity of a dbSwing model.
Therefore, these components only have binders, which are used to synchronize
a component with the dataset column it's bound to.
-
A slider handles more than one data value, but always a contiguous range
of numbers, not an arbitrary collection of values. It too can get
by without a dbSwing model, but needs a binder.
-
A list works with a one-dimensional array of data. The source of
the data in the list is usually different from the dataset that changes
or responds to changes in the list selection. So JdbList has both
a model and a binder.
-
In contrast to a JdbList, the dataset that fills a JdbTable and the dataset
that responds to navigation and edits in the table are one and the same.
Therefore, a JdbTable only needs a single component, DBTableModel, to link
it to its dataset.
-
dbSwing cannot fill a JdbTree from a dataset, so it has no tree model.
However, dbSwing can synchronize a JdbTree's selection with a data set
and modify the dataset when the selection is changed. It uses a tree
binder to do this.
DW203: When should I use a dbSwing model or
binder? When should I not use one?
A dbSwing visual component delegates almost all of the work of being
data-aware to the appropriate model and/or binder. When you use a
dbSwing visual component, there's no point in connecting it to a dbSwing
model and/or binder explicitly - let the component take care of that task
itself. But when you use a Swing-based component from another component
set, the easiest way to work with data from a JBuilder dataset is
to use the appropriate dbSwing model and/or binder.
DW204: How do I use a dbSwing model with my
non-dbSwing visual component?
Instantiate the dbSwing model, set its dataSet property, set its columnName
property (except for JdbTable), and set your component's model property
to it.
DW205: How do I use a dbSwing binder with
my non-dbSwing visual component?
Usually your component will extend a Swing component. In that
case, instantiate the corresponding binder and set the property whose name
is a component name. For example, if MyList is a class that extends
javax.swing.JList, use a DBListDataBinder with its jList property set to
your instance of MyList.
If your component doesn't extend a Swing component, it must at
least implement a Swing model interface (or two interfaces,
if it uses a second model to manage selection). In this case, set
the model property or properties of the appropriate binder.
For instance, if your component implements javax.swing.ListModel and ListSelectionModel,
use a DBListDataBinder and set its listModel and listSelectionModel properties.
In either case, JBuilder can't open the dataset for you as it usually
does when a visual component bound to a dataset is realized. You
will probably have to add code near the end of your class's jbInit method
to open the dataset.
DW206: What are the JdbNav components all
about?
"Nav" components are data-aware and display values from a dataset in
the usual way. When the value in a Nav component is changed, however,
the new value is not written to the dataset; instead, the dataset is navigated
to a row with a matching value.
-
JdbNavList and JdbNavComboBox: when you use JdbTextFields to display
one row of a dataset at a time, a JdbNavList or JdbNavComboBox can be used
to select a row and navigate to it quickly. Unlike JdbList and JdbComboBox,
a JdbNavList or JdbNavComboBox is always filled with the contents of the
column it navigates in.
-
JdbNavTree works just as you would expect a Nav version of JdbTree to work.
-
JdbNavField is analogous to JBCL's LocatorControl. When you enter
a value in a JdbNavField, the dataset it is bound to is searched for a
row with that value. JdbNavField supports incremental searching in
String columns and can find the previous/next match.
-
JdbNavToolBar is a little different from other Nav components. It
does not display data from its dataset, though it does display status information
by enabling or disabling buttons. When manipulated, it can perform
navigation and other operations on its dataset.
DW207: Why don't I see data in a component
that's connected to a dataset by a dbSwing binder?
If you've connected a dbSwing binder to a component by setting its model
property, JBuilder cannot open the binder's dataset for you. (The name
of the property and even the number of properties depends on the binder.
For example, DBListDataBinder has listModel and listSelectionModel properties.)
Write code to open the binder's dataset just after your jbInit() code finishes
executing. Note that you only use a binder's model property to connect
it to a component that does not extend a Swing component. The usual
way to connect a DBListDataBinder to a component that extends JList, for
example, is to set the binder's jList property.
DW208: Why don't I see data in a component
that's connected to a dataset by a dbSwing model?
A component that uses a DBListModel or DBTableModel as its model may
not see data even when it is properly bound to a dataset and the data set
is open. The model tries to postpone data access as late as possible.
Occasionally, particularly when it's rebound at runtime, it delays the
data fetch too long. To force the model to initialize, call a method
on it. For instance, for DBTableModel, call getRowCount().
Scrolling
DW250: Why doesn't my JdbTable, JdbList, etc.
scroll?
Swing and dbSwing components do not have built-in scrolling behavior.
Whenever a component should be scrollable, put a Swing JScrollPane or a
dbSwing TableScrollPane in your design first, then place the component
in the scroll pane. You can set properties to specify when scrollbars
are used, but the default behavior is usually what you want.
DW251: What are the advantages of using TableScrollPane
instead of JScrollPane?
dbSwing's TableScrollPane extends JScrollPane with additional support
for JdbTables. Its scrollbars fill the corners that would otherwise
be empty with a scrollable table and it has additional paint and scroll
options that are especially useful when a table has many rows. TableScrollPane
is most useful for tables but can contain any scrollable component.
Displaying
and editing data
DW300: Why are my edit masks ignored?
dbSwing does not support edit masks. Display masks - either the
ones you specify or the defaults - are used to parse and format data values.
There is no character by character validation of input. If you need
edit mask support, you may want to consider using JBCL components instead
of dbSwing. dbSwing will provide support for edit masks in a future
version of JBuilder.
DW301: How do I display an image?
Use a JdbLabel component. Set its icon property and, assuming
you don't want to display any text, set its text property to null.
To allow a new image to be selected at runtime, set the iconEditable property
true.
JdbTable
DW350: How do I display a picklist of choices
in a column of a JdbTable?
JdbTable in JBuilder 3.0 does not include a table cell editor that behaves
like a combo box. This will be included in a future version of JBuilder.
DW351: I don't want to display all the columns
of my dataset in my JdbTable. How do I hide columns?
Call the JdbTable's setHiddenColumns() method, passing it an array of
ints that represent the columns to be hidden.
DW352: How do I set properties on a column
of a JdbTable?
Usually you set properties on com.borland.dx.dataset.Column objects
and let JdbTables and other components inherit them. Here, we're
concerned specifically with the properties of a column in a table component,
which are stored in a TableColumn object. A JdbTable has a TableColumn
for each column in its dataset. Ordinarily, they're created by default,
but you can create TableColumn objects, set their properties, and pass
them to your JdbTable through its setCustomizedColumns() method.
This is how you control column width and resize behavior or add cell renderers
and editors to a table
When instantiating a TableColumn, remember that it and other JTable-related
classes are in the javax.swing.table package. When you call setCustomizedColumns(),
you must provide a TableColumn object for each column up to and including
the right-most one you want to manipulate. Some may just be placeholders,
of the form "new TableColumn(n)" where n is the column's ordinal. When
figuring ordinals, don't count hidden columns.
DW353: How do I change the default order of
columns in a JdbTable?
One way to change the order of columns in a dataset is by setting their
preferredOrdinal properties. That will change their order everywhere:
when you refer to a column by number instead of name, whenever you display
the dataset in a JdbTable, etc.
To change the column order only in a JdbTable, call its setCustomizedColumns()
method, passing an array of TableColumn objects in the desired order.
For example, if a dataset has three columns, this statement will reverse
their order:
jdbTable1.setCustomizedColumns(new TableColumn[]
{
new TableColumn(2),
new TableColumn(1), new TableColumn(0) } );
DW354: How do the setHiddenColumns() and setCustomizedColumns()
methods interact?
With both methods, you use integers to represent column ordinals.
Hidden columns are processed first, so the integers are just the ordinals
of data set columns. Only the remaining, visible columns are counted
when numbering Customized columns. All column counts start at 0.
This code will hide every other column in a six-column dataset starting
with the second, then reverse the order of the visible columns:
jdbTable1.setHiddenColumns(new int[] { 1, 3,
5 } );
jdbTable1.setCustomizedColumns(new TableColumn[]
{
new TableColumn(2), new TableColumn(1),
new TableColumn(0) } );
DW355: I'm having trouble using an application
that contains a JdbTable:
- sometimes the table loses focus unexpectedly
- clicking on a row in the table won't move focus
to it
- double-clicking in the table won't begin field
edit.
What's happening? How can I fix it?
Click anywhere on your JdbTable and examine the row that gets focus.
A field in that row is still in edit mode (indicated by an inconspicuous
border around it) and contains an invalid data value. To enforce
dataset constraints, JdbTable must refuse to accept that value. Unfortunately,
the Swing architecture doesn't make it easy for JdbTable to keep focus
in a field until its value is acceptable. This results in the odd
behavior you see: you can tab from one component to another, and
even edit data, but when focus arrives at the JdbTable, it's restricted
to one row, and only one field in that row may be edited. Fix the
invalid value in that field or use Esc to cancel the edit. To prevent
this behavior, always press Enter to finish editing a field in a JdbTable.
Navigation out of an edited field will work better in the next version
of dbSwing. Sun is also working on the problem. We expect it
to be completely resolved in the next major JDK release.
DW356: How do I set intercell spacing (the
margins between grid lines and data)?
When a JdbTable is realized, it replaces its default ColumnModel with
a ColumnModel based on the dataset it's bound to. When this happens,
the horizontal component of the table's intercellSpacing property is lost.
To set this horizontal component, internally called columnMargin, after
a JdbTable has its new ColumnModel, replace a JdbTable definition like
this:
JdbTable jdbTable1 = new JdbTable();
with code like this:
JdbTable jdbTable1 = new JdbTable() {
public void addNotify() {
super.addNotify();
// Set horizontal intercell
spacing, in pixels
getColumnModel().setColumnMargin(5);
// Optionally, set vertical
intercell spacing
rowMargin = 5;
}
};
In this sample we also set the vertical intercell spacing, but that's
less useful since adjusting the row height at runtime overrides it.
Text components
DW400: How can I make a JdbTextField display
a drop-down picklist?
You can't, but you can display the data in a JdbComboBox instead.
Bind the JdbComboBox to a column whose picklist property is set, or set
the column's items property. JdbComboBox can display a single- or
multi-column picklist.
DW401: How do I limit the number of characters
entered in a JdbTextField?
dbSwing will do this for you when
-
The component is a JdbTextField, JdbTextArea, or column of a JdbTable
-
The component or column is bound to a String column
-
The column gets its data from a server
-
The server knows the maximum length for values in the column and passes
this information to JBuilder (as the value of the column's precision property)
If these conditions aren't met, you can set a limit yourself with code
like this:
((DBPlainDocument) jdbTextField1.getDocument()).setMaxLength(25);
See HintsAndTips.txt in your JBuilder3 directory for more information.
Tree components
DW450: Why can't I fill a JdbTree with data
from a dataset by setting properties?
Ideally, a tree, like a list, would be data-aware in two ways:
- it would be filled with data from one dataset
- its selection would be synchronized with the current
row of a dataset (probably a different dataset)
But there is no single, obviously correct way to map data from a dataset
to a tree. The problem is that a dataset is tabular while a tree
is inherently hierarchical. So dbSwing currently doesn't provide support
to fill a tree from a dataset, though we're thinking about what we might
do here in the future.
To fill the tree, you have to write code that understands your representation
of hierarchical data. JdbTree is still considered a data-aware component
because selection in the tree writes to the current row of the bound-to
dataset and navigation in the dataset changes selection in the tree.
Its dataSet and columnName properties specify this binding.
DW451: How do I fill a JdbTree with data?
Create a tree node that will be the root of your JdbTree and pass it
to the constructor of a tree model. Then create other nodes and attach
them as the root's children, create still more nodes and make them children
of the root's children, and so on. Finally, set a JdbTree's model
property to the tree model. This is not hard, but there are a number
of inter-related decisions you have to make:
-
Where does the data to fill the tree come from? In some cases, you
might decide to hard-code it in your application. In others, it might
come from a dataset.
-
If the data comes from a dataset, how is the tree's hierarchy represented?
Presumably each row in the dataset will become a node in the tree. You
might have a column whose values represent the path to the node.
Or you might store only the node's parent in this column, and follow parent
links recursively to determine the node's position in the tree. If
the tree is not deep, you could also use a different dataset for each level
of the tree.
-
In what order will the data be loaded into the tree? For a very large
tree, finding the parent as each new node is added might be slow.
-
What data will be stored in each node of the tree? If the "user data
object" in each node is not a String, you have to provide a cell renderer
and define equality between the user data and the values in the bound-to
dataset column.
-
What data will be stored in the column of the dataset that the tree is
bound to? If the value is an Object instead of a String, you may
have to provide a cell renderer and override the default read and write
operations.
The HtmlViewer sample in samplescomborlandsamplesdbswinghtmlviewer
has sample code to build a JdbTree. The content of its tree is a
simple help system that discusses these issues in more detail.
List and
combo box components
DW500: How do I fill a JdbList or a JdbComboBox's
drop-down with values?
You can provide a hard-coded list of value by setting the list or combo
box's items property. This works well when the number of values is
small and they seldom change. Often, however, it isn't quite what
you want. Often your list of values exists in a column of a dataset,
possibly one that you edit frequently, and you want to fill the list or
combo box with the current contents of this column. You may think,
looking at the properties available on JdbList and JdbComboBox, that this
isn't possible. (They have dataSet and columnName properties, of
course, but those properties are used to specify where the value selected
from the list should be written.) Here's the answer to the puzzle:
the necessary property is a property of the Column object that the JdbList
or JdbComboBox is bound to. To fill the list or combo box from a
dataset, set the column's picklist property.
DW501: How do I set a dataset Column's picklist
property?
This is really a DataExpress question, but it comes up frequently when
working with dbSwing list and combo box components.
A picklist is defined by a PickListDescriptor. Because there are
several powerful picklist options, picklist setup is a bit complicated.
We give a conceptual overview, an example, and steps.
Conceptual overview: You want to specify the set of valid values
that may be entered in a column of a dataset. Call this column the
"base column", since it is the column whose picklist property is set, and
call its dataset the "destination dataset". A column of another dataset
contains the valid values. This is the "picklist display column"
of the "picklist dataset". When the base column is bound to a list
or combo box component, the component displays values from the picklist
display column. When the application user selects a value in the
list or combo box, the effect is to point to a row in the picklist dataset.
A value from a column of this row (the "picklist column") is copied into
the "destination column" of the destination dataset.
This probably sounds more complicated than it needs to be. That's
because this description assumes that there's only one picklist display
column, one picklist column, and one destination column. In fact,
each can be an array of columns. Sometimes you want to display several
columns in a JdbComboBox's drop-down to help the user select the right
value. (JdbList can only display one column.) Sometimes you
want to copy values from several picklist columns into corresponding destination
columns (a customer address into the billing address of an order, for instance).
It might even happen that the picklist display column is not the picklist
column - that is, you display values from one column in the list or combo
box but write data from a different column of the picklist dataset into
the destination dataset. PickListDescriptor contains enough information
to support these options and more.
Example: Suppose that the only values you want to allow
in the Customer Number column of your Orders dataset are IDs of your company's
customers. To enforce this, you set the pickList property of the Customer
Number column in the Orders dataset. Your Customers dataset provides
the list of customer numbers, so it is the picklist dataset. This
list is displayed in a JdbComboBox. When a value is selected from
it, the value is written to the current row of the Orders dataset.
Better yet, to make selecting the right customer easier, you might display
the customer's name as well as ID in the list. Also, you might copy
the selected customer's entire address from the Customer dataset into the
current row of Orders.
Steps to define a picklist in the designer:
-
In the component tree, select the column that will be bound to a list or
combo box.
-
In the Inspector, open the editor for the column's pickList property.
-
Select the picklist dataset - the dataset that contains the values used
to fill the list or combo box - from the drop-down list of datasets.
Its columns are now displayed in a table under the heading "source column".
-
Click the "Show in picklist" checkbox for each column from the picklist
dataset that should be displayed in the list or combo box.
-
For each column in the picklist dataset whose value should be copied to
the destination dataset, drop down the list in the "destination column"
field and select the column to copy to. Only columns of compatible
data types are listed.
A picklist is an editing tool - it forces the field value to be one of
a set of valid values. The picklist mechanism can also be used in
display, to show a column of values from the picklist dataset. This
is called a "lookup". For more on picklists and lookups, see the
JBuilder documentation or the Picklists sample in samplescomborlandsamplesdbswingpicklists.
DW502: How do I display multiple columns in
a JdbComboBox's drop-down?
When you set the pickList property of the column that the combo box
is bound to, select more than one picklist display column. The JdbComboBox
will display all the selected columns. (JdbList can only display
one column, the first one in the list.)
DW503: How do I control the width of
a JdbComboBox's drop-down?
By default, a JdbComboBox's drop-down is the same width as the component.
To control its width, set the width property of the column or columns in
the picklist dataset that are displayed in the drop-down. This property
specifies the number of average width characters of an average font that
will be visible. You may need to fine tune it to match your configuration.
The overall width of a multi-column drop-down will be the sum of the
column widths. If this is too wide, set the JdbComboBox's dropDownWidth
property. Like other size properties of components, this specifies
a number of pixels. The drop-down automatically gains a horizontal
scrollbar if the sum of the column widths is greater than the dropDownWidth.
When you set dropDownWidth, the size of the component itself may change
to match this width. This will depend on your layout. If necessary,
set the JdbComboBox's preferredSize property as well.
Button components
DW550: How do I group radio buttons so only
one of them can be selected at any time?
-
While in the designer, open the BeanChooser (it's just to the left of the
palette).
-
Select javax.swing.ButtonGroup.
-
Drop a ButtonGroup into the component tree.
-
In the component tree or the designer, multi-select all the buttons in
the group.
-
In the Inspector, set the buttons' buttonGroup property to the new ButtonGroup
object.
DW551: How do I force all the radio buttons
in a group to be unselected when a new row is inserted?
This assumes that the radio buttons represent possible values for a
column of a dataset. Set the column's default property to a value that
means "Undefined". For example, if the column's data type is Integer
or Short, the default might be 0. Place all the radio buttons in
a FlowLayout. Add an extra button to the group and set its selectedDataValue
property set to the default value. Make this button invisible. Because
it's in a FlowLayout, it won't take any space, leaving the visible ones
nicely centered. It will become the selected button each time a new
row is inserted, causing all the visible buttons to be unselected.
General runtime
topics
DW600: What JDKs can I use with dbSwing?
dbSwing requires Java 2's JDK 1.2 or a newer JDK.
DW601: Contextual (popup) menus don't seem
to work very well.
One of the key attributes of Swing is that it's lightweight. However,
a contextual menu can extend beyond the bounds of the component it's associated
with, and therefore can't always be lightweight. Perhaps as a result,
contextual menus have been troublesome in Swing. You'll find that
dbSwing's contextual menus can't be operated from the keyboard and that
their submenus are not visible when both the menu and the submenu fit within
the bounds of their table or text component. However, once you learn
to avoid these quirks, contextual menus are quite useable.
|