Download.oracle.com




















If you are using a table without a scroll pane, then you must get the table header component and place it yourself. For example:. By default, all columns in a table start out with equal width, and the columns automatically fill the entire width of the table. When the table becomes wider or narrower which might happen when the user resizes the window containing the table , all the column widths change appropriately.

When the user resizes a column by dragging its right border, then either other columns must change size, or the table's size must change. By default, the table's size remains the same, and all columns to the right of the drag point resize to accommodate space added to or removed from the column to the left of the drag point.

To customize initial column widths, you can invoke setPreferredWidth on each of your table's columns. This sets both the preferred widths of the columns and their approximate relative widths. For example, adding the following code to SimpleTableDemo makes its third column bigger than the other columns:. As the preceding code shows, each column in a table is represented by a TableColumn object. TableColumn supplies getter and setter methods for the minimum, preferred, and maximum widths of a column, as well as a method for getting the current width.

For an example of setting cell widths based on an approximation of the space needed to draw the cells' contents, see the initColumnSizes method in TableRenderDemo. When the user explicitly resizes columns, the columns' preferred widths are set such that the user-specified sizes become the columns' new current widths.

Instead, the existing preferred widths are used to calculate new column widths to fill the available space. You can change a table's resize behavior by invoking setAutoResizeMode. In its default configuration, a table supports a selection that consists of one or more rows.

The user can select a contiguous range of rows or an arbitrary set of rows. The last cell that the user indicated gets a special indication; in the Metal look and feel, the cell is outlined. This cell is known as the lead selection ; it is sometimes called "the cell with the focus" or "the current cell". This example program presents the familiar table, and allows the user to manipulate certain JTable options.

There is also a text pane that logs selection events. In the screenshot below, a user has run the program, clicked in the first row, then control-clicked in the third row. Notice the outline around the last cell clicked; this is how the Metal look and feel highlights the lead selection.

Under "Selection Mode" there are a set of radio buttons. Click the one labelled "Single Selection". Now you can only select one row at a time. If you click on the "Single Interval Selection" radio button, you can select a set of rows that must be contiguous. All of the radio buttons under "Selection Mode" invoke JTable. This method takes a single argument, which must be one of the following constants defined in javax. If you clear all three check boxes setting all three bound properties to false , there is no selection; only the lead selection is shown.

You may notice that the "Cell Selection" check box is disabled in multiple interval selection mode. This is because cell selection is not supported in this mode in the demo. You can specify selection by cell in multiple interval selection mode, but the result is a table that does not produce useful selections. You may also notice that changing any of the three selection options can affect the others.

This is because allowing both row selection and column selection is exactly the same as enabling cell selection. JTable automatically updates the three bound variables as necessary to keep them consistent. To retrieve the current selection, use JTable. To retrieve the coordinates of the lead selection, refer to the selection models for the table itself and for the table's column model.

The following code formats a string containing the row and column of the lead selection:. User selections generate a number of events. Every table object uses a table model object to manage the actual table data. A table model object must implement the TableModel interface. If the programmer does not provide a table model object, JTable automatically creates an instance of DefaultTableModel. This relationship is illustrated below. As the preceding code shows, implementing a table model can be simple.

Generally, you implement your table model in a subclass of the AbstractTableModel class. Your model might hold its data in an array, vector, or hash map, or it might get the data from an outside source such as a database. It might even generate the data at execution time. See below the code taken from TableDemo.

Bold font indicates the code that makes this table's model different from the table model defined automatically for SimpleTableDemo.

A table model can have a set of listeners that are notified whenever the table data changes. Listeners are instances of TableModelListener. In the following example code, SimpleTableDemo is extended to include such a listener.

New code is in bold. In order to fire data change events the table model must know how to construct a TableModelEvent object. This can be a complex procedure, but is already implemented in DefaultTableModel.

If DefaultTableModel is not a suitable base class for your custom table model class, consider subclassing AbstractTableModel. This class implements a simple framework for constructing TableModelEvent objects.

Your custom class simply needs to invoke one the following AbstractTableModel methods each time table data is changed by an external source. Before you go on to the next few tasks, you need to understand how tables draw their cells. You might expect each cell in a table to be a component. However, for performance reasons, Swing tables are implemented differently. Instead, a single cell renderer is generally used to draw all of the cells that contain the same type of data.

You can think of the renderer as a configurable ink stamp that the table uses to stamp appropriately formatted data onto each cell. When the user starts to edit a cell's data, a cell editor takes over the cell, controlling the cell's editing behavior.

By default, the cell renderer for a Number -containing column uses a single JLabel instance to draw the appropriate numbers, right-aligned, on the column's cells. If the user begins editing one of the cells, the default cell editor uses a right-aligned JTextField to control the cell editing.

To choose the renderer that displays the cells in a column, a table first determines whether you specified a renderer for that particular column. If you did not, then the table invokes the table model's getColumnClass method, which gets the data type of the column's cells. Next, the table compares the column's data type with a list of data types for which cell renderers are registered. This list is initialized by the table, but you can add to it or change it.

Currently, tables put the following types of data in the list:. Remember that if you let a table create its own model, it uses Object as the type of every column.

To specify more precise column types, the table model must define the getColumnClass method appropriately, as demonstrated by TableDemo. Keep in mind that although renderers determine how each cell or column header looks and can specify its tool tip text, a renderer does not handle events.

If you need to pick up the events that take place inside a table, the technique you use varies by the sort of event you are interested in:. The next few sections tell you how to customize display and editing by specifying renderers and editors. You can specify cell renderers and editors either by column or by data type.

This section tells you how to create and specify a cell renderer. You can set a type-specific cell renderer using the JTable method setDefaultRenderer.

To specify that cells in a particular column should use a renderer, you use the TableColumn method setCellRenderer.

You can even specify a cell-specific renderer by creating a JTable subclass. It is easy to customize the text or image rendered by the default renderer, DefaultTableCellRenderer. You just create a subclass and implement the setValue method so that it invokes setText or setIcon with the appropriate string or image.

For example, here is how the default date renderer is implemented:. If extending DefaultTableCellRenderer is insufficient, you can build a renderer using another superclass. The easiest way is to create a subclass of an existing component, making your subclass implement the TableCellRenderer interface. Date Published:. File Size:. System Requirements Supported Operating System. On the 'Welcome' page, click Next. If you do not have the prerequisites installed, a message will appear that indicates that you must first install required components.

Make sure that you have installed all prerequisites, and then run the installation program again. Read the End User License Agreement. If you agree to the terms, select "I accept the agreement" option and click Next. On the 'Choose Setup Type' page, click Typical. Click Install. The extension pack adds tables, stored procedures, and user-defined functions. On the 'Ready to Install' page, click Install. A new dialog box will appear, in which you select the target SQL Server platform for the extension pack installation.

The default instance has the same name as the computer. Named instances will be followed by a backslash and the instance name. On the connection page, select the authentication method and then click Next.

On the next page, select Install Utilities Database n , where n is the version number, and then click Next. Oracle Fusion Middleware is complete family of application infrastructure products—from the 1 Java application server t Oracle Fusion Middleware 11g 's hot Oracle Fusion Middleware 11g is Oracle 11g is an Oracle geodatabase After the download is finished After you download , install, Download the application Anniversary Edition and



0コメント

  • 1000 / 1000