ElegantJBeans –Tables
Programmers’ Guide
Table of Content
3.1.1 Setup,
navigation and editing
3.1.2 Formatting
and appearance
3.2.1 Setup,
navigation and editing
3.2.2 Formatting
and appearance
5 Installation
and Registration
5.4.2 Using
with Graphical User Interface of IDE
5.4.3 Using
directly with source code
6.1.1 Creating
an instance of AWTTable
6.1.2 Applying
general formatting features
6.1.3 Applying
advanced features of formatting and appearance
6.1.4 Setting
up row and column header
6.1.5 Configuring
cell renderers and cell editors
6.1.6 Implementing
row-column resizing functionalities
6.1.7 Setting
actions for key strokes
6.1.8 Working
with selection and selection style
6.1.9 Setting
up editing functionalities
6.1.11 Setting
up column widths
6.1.12 Setting
up grid properties
6.1.13 Configuring
search panel
6.1.14 Searching
for information
6.1.16 Setting
visibility of popup menu
6.1.17 Configuring
data with AWTTable
6.1.18 Implementing
paper size and paper type for printing
6.1.19 Setting
up margins and header and footer for printing
6.1.20 Setting
page orientation for printing
6.1.21 Setting
number of copies for printing
6.1.22 Setting
line below header and line above footer for printing
6.1.23 Doing
page setup for printing
6.1.24 Opening
print preview for printing
6.1.25 Handling
bulk print jobs (by controlling spool size)
6.1.26 Implementing
printing – methods to use
6.1.27 Printer
listeners and events
6.1.28 AWTTable
listeners and events
6.2.1 Creating
an instance of JFCTable
6.2.2 Applying
general formatting features
6.2.3 Applying
advanced formatting features for entire table
6.2.4 Implementing
advanced formatting features based on row and column
6.2.5 Setting
up column header
6.2.7 Setting
up cell editors and cell renders
6.2.8 Setting
up grid attributes
6.2.9 Setting
up row heights and row margins
6.2.10 Setting
up column widths and column margins
6.2.11 Working
with selection and selection style
6.2.12 Configuring
editing features
6.2.13 Configuring
data with JFCTable
6.2.14 Setting
up auto resizing feature
6.2.15 Setting
up key strokes insert, delete and enter key
6.2.16 Setting
visibility of popup menu
6.2.17 Configuring
search panel
6.2.18 Searching
for information
7 Product
and Support Information
This preface describes the document. The preface contains the following sections:
|
Section |
Page |
|
Purpose of this document |
4 |
|
Assumptions |
4 |
|
Document Organization |
4 |
|
Conventions Used |
5 |
The purpose of this document is to provide the fundamental skills necessary to productively install, program, integrate, and use the ElegantJ Tables. This document provides both programmer and user perspective to the audience.
This manual assumes that readers are having reasonable level of exposure to fundamentals of Java programming and various architectures.
This document is organized as described in following tables.
Table 1 – Organization of the document
|
Chapter |
Contents |
|
About
ElegantJ Tables |
Ø What’s new Ø Toolkit |
|
Product
demo |
Ø ElegantJ AWT Tables Ø ElegantJ JFC Table |
|
Features |
Ø Installing demo Ø View demo |
|
Installation
and Registration |
Ø Prerequisite Ø Installation Procedure Ø Using with Different IDEs Ø Getting Registered |
|
Programmers’
Guide |
Ø Core components and definitions for different tables Ø Programmer's guide to frequently asked questions |
|
File |
Italic (slanted) type indicates variable values, instruction operands. |
|
[ | ] |
In syntax definitions, brackets indicate items that are optional and braces indicate items that are required. Vertical bars separating items inside brackets or braces indicate that you choose one item from among those listed. |
|
. . . |
In syntax definitions, a horizontal ellipsis indicates that the preceding item can be repeated one or more times. |
|
Get(1) |
A cross-reference to a reference page includes the appropriate section number in parentheses. For example, get(1) indicates that you can find information on the get command in Section 1 of the reference pages. |
|
// |
An explanation of a particular function performed by preceding code. |
ElegantJ Tables is ready to use Table Java Bean that has all you wished to have. Be it a 4 row by 10 column table or a table to represent a database in tabular form, or a spreadsheet solution, you can depend on ElegantJ Tables Bean. From AWT Table and JFC Table, select the one that suits your need. Both can handle large volume of data. A cell can be edited as a Textbox, TextArea, CheckBox, Combobox, a Button, an icon, boolean, etc. Manage data with maximum flexibility using Bean's formatting, editing, navigating and information handling features. Ready to use Search Panel, feature of sorting, functions of insert, add or delete a row as well as column.
ElegantJ Tables Bean offers total control over information management through table. In case you are looking for a table bean that can get you data access too, then check out ElegantJ Data Aware Table bean.
A whole new collection is derived from our Tables collection. ElegantJ Tables is a whole new Java Beans collection designed to cater when you wish to work with data in tabular form. Use this bean specially when you do not need Data Aware Tables. Read Overview for more information.
In case you are using evaluation, an Evaluation dialog used to popup every 10 minutes. This dialog will now appear only once, making evaluation without interruption.
ElegantJ Tables is shipped with two set of Beans - ElegantJ Tables Beans.
Ø AWT Tables Beans
o ElegantJ AWT table (awttables.jar)
Ø JFC Tables Beans
o ElegantJ JFC Table (jfctables.jar)
Ø Row and column header attributes can be customized in Elegant AWTTables Java Bean.
o With ElegantJ AWTTable Java Bean, you can customize attributes like
§ Header background
§ Text
§ Column header height and row header width
§ Make header visible or invisible.
o You can also resize column / row from header in this JavaBean.
Ø Provides wide range of selection attributes.
o You can select a row, column, row interval as well as column interval in ElegantJ Java Bean.
o In this JavaBean, you have an option to enable or disable row and column selections. Selection can be restricted to single (row or column or cell) or a range.
Ø In this JavaBean, you can control editability at table, row or column level.
Ø Easy Resizing - resize from column header, row header or cell. Also size row or column on double-click.
Ø Auto-scroll on mouse drag.
Ø Update table in real-time during dragging.
Ø Apply Cell Renderers and Cell Editors on entire table or selected rows or columns.
Cell Renderers
Cell renderer is a component which renderers the cell. You can apply any component as a cell renderer for ElegantJ Java Bean. This renderer can be applied at table level, column level or at Row level. ElegantJ AWTTables is shipped with following Cell Renderers -
o Text Renderer
o TextArea Wrap Renderer
o Checkbox Renderer
o Combobox Renderer
o Button Renderer
Cell Editors
This component is used to edit a cell. You can apply any component as a cell editor for ElegantJ AWTTable Java Bean. This editor can be applied at Table level, Column level and low level. ElegantJ AWTTable Java Bean is shipped with following editors -
o Text Editor
o TextArea Editor
o Checkbox Editor
o Combobox Editor
Ø Delete a row, insert a row and add a row with Delete / Insert / Enter keystrokes respectively.
Ø Ready to use Popup menu with much needed options.
o ElegantJ AWTTable Bean is shipped with ready to use popup menu that can pop on a right-click on mouse.
o You have options to
§ Add a row or column
§ Insert row or column
§ Edit a cell and
§ Sort
Ø Limit resizing of row height and column width by applying a minimum and maximum limit.
Ø ElegantJ AWTTables Java Bean supports general formatting features like Text, background, locale, border, etc.
o ElegantJ AWTTable Java Bean offers you control over
§ Color of text and background
§ Locale
§ Cursor type
§ Enability and visibility
o Border style as None, Simple, Raised and Lowered.
Ø Advance Formatting Features for entire table, selected rows or columns.
o This Java Bean gives you control over color for selected areas of table. You can control background, text, border, font for
§ Entire table
§ Selected rows
§ Selected columns
Ø Better appearance through formatting of Horizontal and vertical grids.
o In ElegantJ AWTTable JavaBean, you control visibility of grid - Vertical grid, horizontal grid.
o Also using ElegantJ AWTTable Java Bean, you can control width and color of the grid.
Ø Customizable Row and column numbers.
Ø You can conduct sort activity in ascending or descending order. This is available on mouse click on column header as well as on right click menu.
Ø Ready to use Search panel with powerful yet flexible search options.
o ElegantJ AWTTable Java Beans offers ready to use Search Panel with placement and formatting options.
o You can choose to place Search Panel on top or bottom.
o You can select color of background and text.
o Search is upwards or downwards, from top or bottom.
o This JavaBean provides search options like
§ Exact match
§ Starts with
§ Ends with
§ Contains.
Ø ElegantJ Java Bean includes an option for Page setup and Print Preview before you print.
o In ElegantJ AWTTable Java Bean, you have options to choose paper size and orientation.
o Setup facility of margins, and header / footer.
o You can set number of copies, date or a variable as part of header or footer in this JavaBean.
o You have ability to preview page before printing in ElegantJ AWTTable Java Bean.
Ø Wide range of selection attributes about things that you can select, how it can be selected.
o ElegantJ JFCTable Java Beans provides you facility to -
§ Select a row, column, row interval, column interval
§ Enable or disable row and column selections.
o Selection can be restricted to single (row or column or cell) or a range (contiguous or discontiguous).
Ø Editability can be controlled at table, row or column level.
Ø Easy Resizing of columns and rows - resize from column header, row header or cell. Also, size row or column on double-click.
Ø ElegantJ JFCTables Java Bean provides you auto-scroll on mouse drag. Update table in real-time with dragging.
Ø Apply Cell Renderers and Cell Editors on entire table or selected rows or columns.
Cell Renderers
Cell renderer is a component which renderers the cell. You can apply any component as a cell renderer for ElegantJ JFCTable Java Bean. This renderer can be applied for whole table, at column level or row level.
ElegantJ JFCTable is shipped with following renderers -
o BooleanRenderer
o CheckboxRenderer
o ChoiceRenderer
o ColorRenderer
o DateRenderer
o DefaultRenderer
o IconRenderer
o MultiLineRenderer
o MultiOptionRenderer
o NumberRenderer
o ProgressRenderer
o RadioButtonRenderer
o TextRenderer
Cell Editors
Cell Editor is a component which is used to edit a cell. You can apply any component as a cell editor for ElegantJ JFCTable bean. This editor can be applied for entire table, selected columns or rows.
ElegantJ JFCTable Bean is shipped with following cell editors -
o BooleanEditor
o CheckboxEditor
o ChoiceEditor
o ColorEditor
o DateEditor
o DefaultEditor
o IconEditor
o MultiLineEditor
o MultiOptionEditor
o NumberEditor
o RadioButtonEditor
o SliderEditor
Ø Delete / Insert / Enter keystrokes to delete a row, insert a row and add a row.
Ø Ready to use Popup menu with much needed options.
o ElegantJ JFCTable JavaBean is shipped with ready to use popup menu that can pop on a right-click on mouse. Menu options are -
§ Add
§ Insert
§ Edit
§ Remove
§ Sort Ascending
§ Sort Descending
o This Java Bean also gives you options to add a row or column, insert row or column, edit a cell or sort.
Ø Limit resizing of row height and column width by applying a minimum and maximum limit. Set row height for all rows or selected ones.
Ø Auto Resize of columns. More»
o You can re-size columns. ElegantJ JFCTable JavaBean provides ability to switch this option on or off.
o This Java Bean also offers facility to auto-resize
§ Next column
§ Subsequent columns
§ Last column
§ All columns.
Ø General formatting features like Text, background, locale, border, etc.
o This Java Bean provides you control over
§ Color of text, background
§ Selection of locale
§ Cursor type,
§ Enability and visibility.
o Using ElegantJ JFCTable JavaBean you can also have swing look and feel features like
§ Lightweight
§ Opaque
§ Tool tip text
§ Double buffering for painting
§ Focus receipt and management
§ Border of component
§ Auto scrolling.
Ø Advance Formatting Features for entire table, selected rows or columns.
o ElegantJ JFCTable JavaBean provides you control over color for selected areas of table
§ Background
§ Text
§ Border
§ Font.
o Also, this Java Bean provides formatting of focus cell background and text and Image icon and font.
§ All these can be applied to
§ Entire table Rows
§ Columns.
Ø Row and column header attributes can be customized in ElegantJ JFCTables Java Bean.
o In ElegantJ JFCTable Java Beans, you can customize row and column header attributes like
§ Header background
§ Text
§ Column header height and row header width
§ Make header visible or invisible
§ Resize column / row from header.
o You can resize columns and rows. You can reorder columns in this JavaBean.
Ø Better appearance through formatting Horizontal and vertical grids.
o Control visibility of grid - Vertical grid, horizontal grid in ElegantJ JFCTable Java Bean.
o Using this JavaBean, also control width and color of Grid.
Ø Customization of Row and column numbers is possible in this Java Bean.
Ø You can conduct sort activity in ascending or descending order. This is available on mouse click on column header as well as on right click menu.
Ø This JavaBean provides you ready to use Search panel with powerful yet flexible search options.
o ElegantJ JFCTable Java Bean has ready to use Search Panel with placement and formatting options.
o You can choose to place Search Panel on top or bottom.
o You can select color of background and text.
o In this JavaBean, search can be performed upwards or downwards, from top or bottom.
o Search options like -
§ Exact match
§ Starts with
§ Ends with
§ Contains.
Ø Configurable Data Model. Properties you can configure are - total number of columns, total number of rows, column names and Data.
Extracted file(archive) contains demos directory. All the demos are located in this demos directory.
Your classpath environment variables must be set correctly in order to run the demos. For windows users we have provided rundemo.bat file which will run demo directly. All Demo Applets contain HTML file to run an Applet associated with it.
For more information on how to set classpath, refer Installation procedure.
AWT Table demo application
Description: Demonstrates ElegantJ AWT Table application.
To run this demo application,
Go to ElegantJTables\demos\applications\awt\demo1 directory, then execute java -jar tablesawtapp.jar command.
AWT Table demo application using Cell Renderers and Cell Editors
Description: Demonstrates ElegantJ AWT Table application. Various Cell Renderers and Cell Editors are applied.
To run this demo application,
Go to ElegantJTables\demos\applications\awt\demo2 directory, then execute java -jar tablesawtapp.jar command.
JFC Table demo application
Description: Demonstrates ElegantJ JFC Table application.
To run this demo application,
Go to ElegantJTables\demos\applications\jfc\demo directory, then execute java -jar tablesjfcapp.jar command.
Note: For windows users we
have provided the rundemo.bat file to run respective demo application.
Before installing ElegantJBeans, please ensure that your computer system and development environment are setup and working as per expectations. Person evaluating ElegantJBeans is expected to be able to write and execute simple JAVA applications.
We provide free pre-purchase technical support to help you complete process of evaluation. Mail to support@elegantJBeans.com for pre-purchase technical support.
To be able to use ElegantJBeans, your computer systems are required to have -
Ø An IDE that supports Java 2 or higher, or
Ø JDK 1.2.2 or higher
Please note that evaluation version of ElegantJBeans cannot be deployed for commercial, non-commercial or any other purpose in any possible way. You may not build any software, applets or applications for distribution with evaluation version of ElegantJBeans.
This evaluation version is to be solely used by you to evaluate suitability of ElegantJbeans for your needs. For more details please go through License Agreement.
On extracting ejtables_v1.zip, following directories will be created inside ElegantJTables directory -
Directory [jars] contains Jar file(s)
Directory [demos] contains demo application(s) with source code
Directory [docs] contains path for document(s) access
Installing on Windows 95/98
To include ElegantJ Beanery in CLASSPATH, add following statement to your autoexec.bat file,
set CLASSPATH= %CLASSPATH%;C:\ELEGANTJ\<ELEGANTJ_BENARY_HOME>
\jars\<ELEGANTJ_BEAN>.jar;
Restart Windows to make changes effective.
Installing on Windows NT / 2000
Go to Control Panel and select System. You will find environment variables on Environment tab in Windows NT systems and on Advanced tab in Windows 2000 systems.
Find CLASSPATH environment variable or create it.
To include ElegantJ Beanary in the CLASSPATH, specify or add following value for variable -
[EXISTING-CLASSES];C:\<ELEGANTJ_BEANARY_HOME>\jars\<ELEGANTJ_BEAN>.jar
Installing on UNIX / Linux
Before you begin using ElegantJ Beanary, you must manually configure CLASSPATH environment variable. CLASSPATH must point to the location of classes and installation directory.
For example, to set CLASSPATH for ElegantJ Beanary,
setenv CLASSPATH .:/usr/local/<ELEGANTJ_BEANARY_HOME>/jars/
<ELEGANTJ_BEAN>.jar:
If you are using Bourne Shell, commands are,
CLASSPATH= $CLASSPATH:.:/usr/local/<ELEGANTJ_BEANARY_HOME>/jars/
<ELEGANTJ_BEAN>.jar:export CLASSPATH
Follow the steps given below to create a new category and install Bean into Borland JBuilder.
Create a New Category
Ø Click menu Tools > Configure Palette. It opens Palette Properties dialog box.
Ø Click Add button. It opens Add Page Dialog box. Specify name (for example ElegantJ) and click OK. New Category gets created.
Create New Library and Install / Import Bean
Ø On Palette Properties dialog box, click Pages tab. Select Newly created page (for example ElegantJ).
Ø Click button Select Library. Select a Different Library dialog box opens.
Ø Click New button on Select a Different Library dialog box. New Library Wizard dialog box opens.
Ø Specify name for library and click Add button. Select One or More Directory dialog box opens.
Ø Select directory where jar files are located, or select jar file to be imported. Click OK. Dialog box gets closed and New Library Wizard dialog box appears in front.
Ø Click OK on New Library Wizard. It opens Select a Different Library dialog box.
Ø Confirm that newly created library is selected. Click OK. It opens Add Components under Palette Properties.
Ø Click Add from Selected Libraries button. It opens Results dialog box, click OK.
Ø Results dialog box disappears. Click OK on Palette Properties dialog box.
Ø Beans are ready to use.
Follow the steps given below to import ElegantJBeans in Oracle JDeveloper.
To Import beans into a project
Ø Click menu Project > Project Settings. It opens Project Settings dialog box.
Ø Click Libraries entry appearing on the pane on left side.
Ø Click New button. It opens New Library dialog box.
Ø In Library Name entry box, specify Library name. In Location entry box, specify location where you want the library to be located. In Class Path entry box, specify path of jar file of Bean. Browse the location by clicking Edit... button if required.
Ø Click OK. The library you selected appears in Available Libraries list of Project Properties dialog box.
Ø Select the library you want and click > button to add it to Selected Libraries list.
Ø Click menu Tools > Configure Component Palette. It opens Configure Component Palette dialog box.
Ø To create a new palette page, click New Page... button. It opens New Palette Page dialog box. Specify Page Name and Page Type. Click OK. A new page with specified name will be created.
To add component to page
Ø On Configure Component dialog box, from Pages list, select the page and click Add Component button. It opens Add JavaBeans dialog box with available libraries.
Ø Select a library from Library combo box.
Ø Browse the hierarchy and select a component. It displays preview of icon for selected component. Click OK. It shows Palette Confirmation dialog box.
Ø Click Yes on Palette Confirmation dialog box to complete the process.
Ø Beans are ready to use.
You can purchase a license from our web site www.elegantJBeans.com
You can also contact our sales team sales@elegantJBeans.com
On purchasing a license, you will receive a mail having your license key.
License key can be applied to ElegantJ Java Bean using any of the following ways,
Ø Using with Graphical User Interface of IDE
Ø Using directly with source code
While Designing an application or an applet graphically in an Integrated Development Environment, you will find a property named licensekey along with other properties of the bean. Specify key (serial number) in LicenseKey Property.
Note: Instead of typing the
license key, we suggest you to copy the license key from mail and paste it at
required place. Make sure that the
selection does not have any leading or trailing spaces.
When you use the Bean within code, you need to set the key by providing value in setLicenseKey Method.
Note: Instead of typing the
license key, we suggest you to copy the license key from mail and paste it at
required place. Make sure that the
selection does not have leading or trailing spaces.
ClassName object = new ClassName();
object.setLicenseKey("LICENSE_KEY");
Example
AWTTree awtTree = new AWTTree();
awtTree.setLicenseKey("LICENSE_KEY");
ElegantJ AWTTable can be created in following ways,
Ø To create AWTTable with zero rows, zero columns and with printing support,
com.elegantj.awt.table.AWTTable awtTable = new com.elegantj.awt.table.AWTTable();
Ø To create AWTTable with specified rows and columns. Printing support (required or not) is also specified.
int rowCount = 10;
int columnCount = 5;
boolean isAllowPrinterSupport = false;
com.elegantj.awt.table.AWTTable awtTable =
new com.elegantj.awt.table.AWTable(rowCount, columnCount, isAllowPrinterSupport);
AWTTable has following general formatting features:
Ø Font
Ø Background
Ø Foreground
Ø Visibile
Ø Enabled
Ø Locale
Ø Cursor
Ø Bounds
Ø Border
Ø To set Font,
awtTable.setFont
(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12)); // sets font size to dialog, plain and of size 12
Ø To set Background,
awtTable.setBackground(java.awt.Color.cyan); // sets background color as cyan
Ø To set Foreground,
awtTable.setForeground(java.awt.Color.black); // sets foreground color as black
Ø To set Visibility,
awtTable.setVisible(true); // sets visibility to true - makes table visible
Ø To set Enability,
awtTable.setEnabled(true); // sets the enability to true - to make changes in table possible
Ø To set Locale,
awtTable.setLocale(java.util.Locale.ENGLISH); // sets locale to english
Ø To set Cursor,
awtTable.setCursor
(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); // sets the cursor to hand cursor
Ø To set Bounds,
int x = 5;
int y = 5;
int width = 300;
int height = 200;
awtTable.setBounds(x, y, width, height); // sets bounds to x, y, width and height
Ø To set Border,
awtTable.setBorder(new
com.elegnatj.editors.AWTBorder
(com.elegnatj.editors.AWTBorder.SIMPLE, 2,
java.awt.Color.black));
// sets border to simple, point size = 2 and border color is black
Following properties can be set for entire table -
Ø BackgroundNonSelectionColor
Ø BackgroundSelectionColor
Ø TextNonSelectionColor
Ø TextSelectionColor
Ø BorderSelectionColor
Ø Font
Ø CellRenderer
Ø CellEditor
Ø To set BackgroundNonSelectionColor,
awtTable.setBackgroundNonSelectionColor(java.awt.Color.cyan); // sets background non selecton color as cyan
Ø To set BackgroundSelectionColor,
awtTable.setBackgroundSelectionColor(java.awt.Color.blue); // sets background selection color as blue
Ø To set TextNonSelectionColor,
awtTable.setTextNonSelectionColor(java.awt.Color.black); // sets text non selection color as black
Ø To set TextSelectionColor,
awtTable.setTextSelectionColor(java.awt.Color.yellow); // sets text selection color as yellow
Ø To set BorderSelectionColor,
awtTable.setBorderSelectionColor(java.awt.Color.red); // sets border selection color as red
Ø To set Font,
awtTable.setFont
(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12)); // sets font for whole AWTTable as Dialog, plain and of size 12
Ø To set cell renderer,
Here is a list of basic renderers shipped with this Bean -
o com.elegantj.awt.table.TextRenderer
o com.elegantj.awt.table.CheckboxRenderer
o com.elegantj.awt.table.ChoiceRenderer
o com.elegantj.awt.table.TextAreaWrapRenderer
o com.elegantj.awt.table.TextAreaRenderer
com.elegantj.awt.table.CheckboxTableCellRenderer
renderer = a
new com.elegantj.awt.table.CheckboxTableCellRenderer();
awtTable.setCellRenderer(renderer);
Ø To set cell editor,
Here is a list of basic editors shipped with Bean -
o com.elegantj.awt.table.TextEditor
o com.elegantj.awt.table.CheckboxEditor
o com.elegantj.awt.table.ChoiceEditor
o com.elegantj.awt.table.TextAreaEditor
com.elegantj.awt.table.CheckboxTableCellEditor
editor =
new
com.elegantj.awt.table.CheckboxTableCellEditor();
awtTable.setCellEditor(editor);
Following attributes can also be set to specific row (s) or column (s) -
Ø BackgroundNonSelectionColor
Ø BackgroundSelectionColor
Ø TextNonSelectionColor
Ø TextSelectionColor
Ø BorderSelectionColor
Ø Font
Ø CellRenderer
Ø CellEditor
Ø To set BackgroundNonSelectionColor on row / column basic,
awtTable.setRowBackgroundNonSelectionColorAt(0,
java.awt.Color.cyan);
awtTable.setColumnBackgroundNonSelectionColorAt(0,
java.awt.Color.cyan);
This sets the background non selection color of row 0 and column 0 as cyan
Ø To set BackgroundSelectionColor on row / column basis,
awtTable.setRowBackgroundSelectionColor(0,
java.awt.Color.blue);
awtTable.setColumnBackgroundSelectionColor(0,
java.awt.Color.blue);
This sets the background selection color of row 0 and column 0 as blue
Ø To set TextNonSelectionColor,
awtTable.setRowTextNonSelectionColor(0,
java.awt.Color.black);
awtTable.setColumnTextNonSelectionColor(0,
java.awt.Color.black);
This sets text non selection color of row 0 and column 0 as cyan
Ø To set TextSelectionColor,
awtTable.setRowTextSelectionColor(0,
java.awt.Color.yellow);
awtTable.setColumnTextSelectionColor(0,
java.awt.Color.yellow);
This sets text selection color of row 0 and column 0 as yellow
Ø To set BorderSelectionColor,
awtTable.setRowBorderSelectionColor(0,
java.awt.Color.red);
awtTable.setColumnBorderSelectionColor(0,
java.awt.Color.red);
This sets border selection color of row 0 and column 0 as red
Ø To set Font,
awtTable.setRowFontAt(0, new
java.awt.Font("Dialog",
java.awt.Font.PLAIN, 12));
awtTable.setColumnFontAt(0, new
java.awt.Font("Dialog",
java.awt.Font.PLAIN, 12));
This sets font of row 0 and column 0 as Dialog, style as plain, size as 12.
Ø To set Cell Renderer,
Here is a list of basic renderers shipped with this Bean -
o com.elegantj.awt.table.TextRenderer
o com.elegantj.awt.table.CheckboxRenderer
o com.elegantj.awt.table.ChoiceRenderer
o com.elegantj.awt.table.TextAreaWrapRenderer
o com.elegantj.awt.table.TextAreaRenderer
com.elegantj.awt.table.CheckboxTableCellRenderer
renderer = new
com.elegantj.awt.table.CheckboxTableCellRenderer();
awtTable.setRowRendererAt(0, renderer);
awtTable.setColumnRendererAt(0, renderer);
This sets renderer for row 0 and column 0 as checkbox.
Ø To set Cell Editor,
Here is a list of basic editors shipped with Bean -
o com.elegantj.awt.table.TextEditor
o com.elegantj.awt.table.CheckboxEditor
o com.elegantj.awt.table.ChoiceEditor
o com.elegantj.awt.table.TextAreaEditor
com.elegantj.awt.table.CheckboxTableCellEditor
editor =
new
com.elegantj.awt.table.CheckboxTableCellEditor();
awtTable.setRowEditorAt(0, editor);
awtTable.setColumnEditorAt(0, editor);
This sets the editor for row 0 and column 0 to checkbox.
With AWTTable, you can set following properties for header -
Ø Sort column on clicking column header
Ø Column/row Header background
Ø Column/row Header foreground
Ø Column/row Header font
Ø Column header height
Ø Row header width
Ø Column header visibility
Ø Row header visibility
Ø Column/row header cell renderer
Ø Column identifiers
Ø IsSizeColumnOnClick - which size column to best fit on clicking gap between two columns
Ø IsSizeRowOnClick - which size row to best fit on clicking gap between two columns
Ø To sort column on clicking column header
awtTable.setSortColumnOnClick(true); // enables sorting of column on column header click
Ø To set header background,
awtTable.setHeaderBackground(Color.gray); // sets header background as gray.
Ø To set header foreground,
awtTable.setHeaderForeground(Color.black); // sets header foreground as black.
Ø To set header font,
awtTable.setHeaderFont(new java.awt.Font("Dialog", Font.BOLD, 12)); // sets header font as dialog, style as bold and size as 12.
Ø To set column header height,
awtTable.setColumnHeaderHeight(30); // sets column header height to 30
Ø To set row header width,
awtTable.setRowHeaderWidth(50); // sets the row header width to 50.
Ø To set column header visibility,
awtTable.setShowColumnHeader(false); // sets column header as invisible.
Ø To set row header visibility,
awtTable.setShowRowHeader(false); // sets the row header invisible.
Ø To set header renderer,
com.elegantj.awt.table.CheckboxTableCellRenderer
renderer =
new
com.elegantj.awt.table.CheckboxTableCellRenderer();
awtTable.setHeaderCellRenderer(renderer);
This sets the header renderer as checkbox.
Ø To set column identifier at the specified index,
awtTable.setColumnIdentifierAt("column 1", 1); // sets the identifier for the column at index 1.
Ø To set column identifiers for all the columns,
java.util.Vector columnIdentifiers =
new java.util.Vector();
columnIdentifiers.addElement("column
1");
columnIdentifiers.addElement("column
2");
columnIdentifiers.addElement("column
3");
awtTable.setColumnIdentifiers(columnIdentifiers);
This sets identifiers for all columns.
Ø To enable sizing of specified column to best fit on double clicking area between two columns,
awtTable.setSizeColumnOnClick(true); // enables resizing of column on double click on area between two columns.
Ø To enable sizing of specified row to best fit on double clicking area between two rows,
awtTable.setSizeRowOnClick(true); // enables the sizing of row to best fit on double clicking area between two rows.
Using AWTTable, you can apply any cell renderer / cell editor to entire table, row wise, as well as column wise.
Here is a list of basic renderers shipped with this Bean -
Ø com.elegantj.awt.table.TextRenderer a
Ø com.elegantj.awt.table.CheckboxRenderer a
Ø com.elegantj.awt.table.ChoiceRenderer a
Ø com.elegantj.awt.table.TextAreaWrapRenderer a
Ø com.elegantj.awt.table.TextAreaRenderer a
Here is a list of basic editors shipped with Bean -
Ø com.elegantj.awt.table.TextEditor a
Ø com.elegantj.awt.table.CheckboxEditor a
Ø com.elegantj.awt.table.ChoiceEditor a
Ø com.elegantj.awt.table.TextAreaEditor a
Ø To set cell renderer for whole table,
com.elegantj.awt.table.CheckboxTableCellRenderer
renderer =
new
com.elegantj.awt.table.CheckboxTableCellRenderer();
awtTable.setCellRenderer(renderer);
This sets checkbox as a cell renderer for whole table.
Ø To set cell editor for whole table,
com.elegantj.awt.table.CheckboxTableCellEditor
editor =
new
com.elegantj.awt.table.CheckboxTableCellEditor();
awtTable.setCellEditor(editor);
This sets checkbox as a cell editor for whole table.
Ø To set cell renderer for specific row,
com.elegantj.awt.table.CheckboxTableCellRenderer
renderer =
new
com.elegantj.awt.table.CheckboxTableCellRenderer();
awtTable.setRowRendererAt(0, renderer);
This sets checkbox as a cell renderer for row 0.
Ø To set cell renderer for specific column,
com.elegantj.awt.table.CheckboxTableCellRenderer
renderer =
new
com.elegantj.awt.table.CheckboxTableCellRenderer();
awtTable.setColumnRendererAt(0, renderer);
This sets checkbox as a cell renderer for column 0.
Ø To set cell editor for specific row,
com.elegantj.awt.table.CheckboxTableCellEditor
editor =
new
com.elegantj.awt.table.CheckboxTableCellEditor();
awtTable.setRowRendererAt(0, editor);
This sets checkbox as a cell editor for row 0.
Ø To set cell editor for specific column,
com.elegantj.awt.table.CheckboxTableCellEditor
editor =
new com.elegantj.awt.table.CheckboxTableCellEditor();
awtTable.setColumnRendererAt(0, editor);
This sets checkbox as a cell editor for row 0.
Advanced Implementation for creating custom Cell Renderers
If you wish to use the custom component as cell renderer, Then you need to create your own class for cell renderer and follow following steps,
Ø extend the cell renderer (your own class for cell renderer) from desired component,
Ø implement com.elegantj.awt.table.TableCellRenderer and then,
Ø override paint(java.awt.Graphics g) method, which is called internally to paint the custom renderer.
Using AWTTable, you can carry out resizing activity from -
Ø Resizing from Column header
Ø Resizing from Row header
Ø Resizing from Cells
Ø To enable resizing from column header,
awtTable.setResizeFromColumnHeader(true); // enables resizing from column header
Ø To enable resizing from row header,
awtTable.setResizeFromRowHeader(true); // enables resizing from row header.
Ø To enable the resizing from cells,
awtTable.setResizeFromCells(true); // enables the resizing from cells.
Here is a list of keystrokes available (for carrying out operations) for use on a cell of AWTTable -
Ø INSERT - for inserting row on insert key
Ø DELETE - for deleting row on delete key
Ø ENTER - for adding row on enter key at the last row position
Ø To enable use of Insert key to inserting a row,
awtTable.setInsertRowOnInsertKey(true);
Ø To enable use of delete key to delete a row,
awtTable.setDeleteRowOnDeleteKey(true);
Ø To enables the adding row on enter key,
awtTable.setAddRowOnEnterKey(true); // this enables adding of row on enter key, it works on last row only.
AWTTable provides two types of selection -
Ø Single selection - com.elegantj.awt.table.SINGLE_SELECTION
Ø Single range selection - com.elegantj.awt.table.SINGLE_RANGE_SELECTION
Ø To set selection style,
awtTable.setSelectionStyle(com.elegantj.awt.table.AWTTable.SINGLE_SELECTION); // sets selection as single selection
Ø To select row(s),
awtTable.setRowSelectionInterval(0, 5); // sets rows 0 to 5 both inclusive as selected
Ø To select column(s),
awtTable.setColumnSelectionInterval(2, 5); // sets columns 2 to 5 inclusive as selected
Ø To clear selection,
awtTable.clearSelection(); // sets selected part of table as not selected.
Ø To set row editability,
awtTabe.setRowEditableAt(0, false); // sets row 0 as not editable
Ø To set column editability,
awtTable.setColumnEditableAt(0, false); // sets column 0 as not editable
Ø To start editing,
awtTable.startEditing(); // start editing of AWTTable
Ø To stop editing,
awtTable.stopEditing(); // stop editing of AWTTable
Ø To cancel editing,
awtTable.cancelEditing(); // cancel editing of AWTTable
Ø To check if table is currently being edited,
boolean isEditing = awtTable.isEditing(); // checks if table is currently being edited
Ø To retrieve row / column that is currently being edited,
int editingRow = awtTable.getEditingRow(); // retrieves row that is currently being edited
int editingColumn = awtTable.getEditingColumn(); // retrieve column that is currently being edited
Ø To set default row height for whole table,
awtTable.setDefaultRowHeight(18); // sets default row height as 18 for whole table
Ø To set row height for a specific row,
awtTable.setRowHeightAt(0, 18); // sets row height as 18 pixels for row at 0th index
Ø To set the default minimum row height for whole table,
awtTable.setDefaultMinimumRowHeight(5); // sets default minimum row height as 5 pixels for whole table
Ø To set the minimum row height for a specific row,
awtTable.setMinimumRowHeightAt(0, 5); // sets minimum row height as 5 pixels for row at 0th index
Ø To set the default maximum row height for whole table,
awtTable.setDefaultMaximumRowHeight(30); // sets default maximum row height as 30 pixels for whole table
Ø To set the maximum row height for a specific row,
awtTable.setMaximumRowHeightAt(0, 30); // sets maximum row height as 30 pixels for row at 0th index.
Ø To set default column width for whole table,
awtTable.setDefaultColumnWidth(100); // sets default column width to 100 pixels for whole table
Ø To set column width for specified column,
awtTable.setColumnWidthAt(0, 100); // sets the column width to 100 pixels for column at 0th index
Ø To set default minimum columm height for whole table,
awtTable.setDefaultMinimumColumnWidth(5); // sets default minimum column width to 5 pixels for whole table
Ø To set the minimum column width for selected column,
awtTable.setMinimumColumnWidthAt(0, 5); // sets minimum column width to 5 pixels for column at 0th index.
Ø To set the default maximum column width for the whole table,
awtTable.setDefaultMaximumColumnWidth(300); // sets default maximum column width to 300 pixels for whole table.
Ø To set the maximum column width for particular column,
awtTable.setMaximumColumnWidthAt(0, 300); // sets maximum column width to 300 pixels for column at 0th index
With ElegantJ AWTTable you can set following properties for grid,
Ø Grid color
Ø Show horizontal grid
Ø Show vertical grid
Ø Horizontal gap
Ø Vertical gap
Ø To set grid color,
awtTable.setGridColor(java.awt.Color.black); // sets the grid color as black
Ø To set visibility of horizontal grid,
awtTable.setShowHorizontalGrid(false); // makes horizontal grid invisible
Ø To set visibility of vertical grid,
awtTable.setShowVerticalGrid(false); // makes vertical grid invisible
Ø To set horizontal gap between two cell,
awtTable.setHorzGap(2); // sets horizontal gap between two cells to 2.
Ø To set vertical gap between two cell,
awtTable.setVertGap(2); // sets vertical gap between two cells to 2.
Ø To set search panel's visibility,
awtTable.setSearchPanelVisible(false); // makes search panel visible
Ø To set background of search panel,
awtTable.setSearchPanelBackground(java.awt.Color.gray);
// sets background color of search panel as gray
Ø To set foreground of search panel,
awtTable.setSearchPanelForeground(java.awt.Color.black);
// sets foreground color of search panel as black
Ø To set font property of search panel,
awtTable.setSearchPanelFont(new
java.awt.Font("Dialog",
java.awt.Font.BOLD, 12));
// sets search panel font as dialog, style as bold
Ø To set location of search panel,
ElegantJ AWTTable supports following tow search panel placements
o com.elegantj.awt.table.AWTTable.TOP - To place it at the top
o com.elegantj.awt.table.AWTTable.BOTTOM - To place it at the bottom
o To set search panel location to top
awtTable.setSearchPanelLocation(com.elegantj.awt.table.AWTTable.TOP); // sets search panel location to top.
Ø To search for specified text with case sensitivity or case insensitivity,
String searchText = "search
text";
boolean isCaseSensitive = false;
int[] rowColumnIndexes =
awtTable.search(searchText, isCaseSensitive);
This searches whole AWTTable for specified text in case insensitive manner. If specified search text is found, it returns row and column indexes of the cell which contains search text.
Ø To search specified column for the specified text,
String searchText = "search
text";
int searchOnColumn = 0;
boolean isCaseSensitive = false;
int[] rowColumnIndexes =
awtTable.search(searchText, searchOnColumn, isCaseSensitive);
This searches column at index 0 for specified text in case insensitive manner. If specified search text is found, it returns row and column indexes of the cell which contains the search text.
ElegantJ AWTTable supports following Search Options
|
Search Progress from |
Options for search Progress |
|
First cell |
com.elegantj.awt.table.AWTTable. SEARCH_FROM_FIRST_CELL |
|
Last cell |
com.elegantj.awt.table.AWTTable. SEARCH_FROM_LAST_CELL |
|
Selected cell upwards |
com.elegantj.awt.table.AWTTable. SEARCH_FROM_SELECTED_CELL_TO_UP |
|
Selected cell downwards |
com.elegantj.awt.table.AWTTable. SEARCH_FROM_SELECTED_CELL_TO_DOWN |
ElegantJ AWTTable supports following Comparison Options
|
Comparison requirement |
Option for comparison |
|
Search cell for value that starts with given search string |
com.elegantj.awt.table.AWTTable.STARTS_WITH |
|
Search cell for value that ends with given search string |
com.elegantj.awt.table.AWTTable.ENDS_WITH |
|
Search cell for value or its part equals given search string |
com.elegantj.awt.table.AWTTable.CONTAINS |
|
Search cell for value for given string for exact match |
com.elegantj.awt.table.AWTTable.EQUALS |
Ø To perform case sensitive search on specified column for specified search text, search option, comparison option,
String searchText = "search
text";
int searchOption =
com.elegantj.awt.table.AWTTable.SEARCH_FROM_FIRST_CELL;
int comparisonOption =
com.elegantj.awt.table.AWTTable.EQUALS;
int searchOnColumn = 0;
boolean isCaseSensitive = true;
int[] rowColumnIndexes =
awtTable.search(searchText, searchOption, comparisonOption, searchOnColumn,
isCaseSensitive);
This performs case sensitive search on column at index 0, from first cell, for equals comparison option, for specified text. If specified search text is found, then it returns the row and column indexes of cell which contains specified search text.
Ø To perform case insensitive search on specified columns for specified search text, search option and comparison option,
String searchText = "search
text";
int searchOption =
com.elegantj.awt.table.AWTTable.SEARCH_FROM_FIRST_CELL;
int comparisonOption =
com.elegantj.awt.table.AWTTable.EQUALS;
int searchOnColumns[] = new int[]{1, 2, 3};
boolean isCaseSensitive = false;
int[] rowColumnIndexes =
awtTable.search(searchText, searchOption, comparisonOption, searchOnColumns,
isCaseSensitive);
This performs case insensitive search on columns at index 1, 2 and 3, from first cell, for equals comparison option, for the specified text. If specified search text is found, then it returns the row and column indexes of the cell which contains search text.
Ø To sort data in specified column,
int columnIndex = 1;
awtTable.sortColumn(columnIndex);
This sorts data in column at index 1 in ascending-descending-ascending-descending manner. That is, for the 1st time of calling, it sorts in ascending order, on 2nd time in descending order.
Ø To sort specified column in ascending or descending order,
int columnIndex = 1;
boolean sortingOrder = true; // i.e.
ascending
awtTable.sortColumn(columnIndex,
sortingOrder);
This sorts column at the index 1 in ascending order.
Ø To sort multiple columns,
int columnIndexes[] = new int[]{1, 2, 3};
awtTable.sortColumns(columnIndexes);
This sorts column at the index 1, 2 and 3 in ascending-descending-ascending-descending manner. That is, for the 1st time of calling it sorts in ascending order, on 2nd time in descending manner as on in this order.
Ø To sort multiple columns with specified sorting order,
int columnIndexes[] = new int[]{1, 2, 3};
boolean sortingOrders[] = new
boolean[]{true, false, true};
awtTable.sortColumns(columnIndexes,
sortingOrders);
This sorts the 1st column in ascending order, 2nd column in descending order and 3rd column in ascending order.
AWTTable provides a ready to use popup menu, having following functionalities -
Ø Add row / column
Ø Insert row / column
Ø Remove row / column
Ø Edit cell
Ø Sort (ascending / descending) column
All the above popup menu operations takes place on selected row / column / cell.
Ø To set the visibility of the popup menu,
awtTable.setShowPopupMenu(true); // allows to open the popup menu on right click.
ElegantJ AWTTable provides the following methods to configure data,
Ø To set data with specified 2-dimensional vector as data and 1-dimensional vector as column identifier,
java.util.Vector data = new
java.util.Vector();
java.util.Vector row1Data = new
java.util.Vector();
row1Data.addElement("cell11");
row1Data.addElement("cell12");
row1Data.addElement("cell13");
data.addElement(row1Data);
java.util.Vector row2Data = new
java.util.Vector();
row2Data.addElement("cell21");
row2Data.addElement("cell22");
row2Data.addElement("cell23");
data.addElement(row2Data);
java.util.Vector row3Data = new
java.util.Vector();
row3Data.addElement("cell31");
row3Data.addElement("cell32");
row3Data.addElement("cell33");
data.addElement(row3Data);
java.util.Vector columnIdentifiers = new
java.util.Vector();
columnIdentifiers.addElement("column1");
columnIdentifiers.addElement("column2");
columnIdentifiers.addElement("column3");
awtTable.setData(data, columnIdentifiers);
This sets data with specified 2-dimensional vector as data and 1-dimensional vector as column identifier.
Ø To set data with specified 2-dimensional object array as data and 1-dimensional object array as column identifier,
Object[][] data = new Object[][]
{
{"cell11", "cell12",
"cell13"},
{"cell21",
"cell22", "cell23"},
{"cell31",
"cell32", "cell33"}
};
Object[] columnIdentifiers = new Object[]
{"column1", "column2", "column3"};
awtTable.setData(data, columnIdentifiers);
This sets specified 2-dimensional object array as data and 1-dimensional object array as column identifiers.
Ø To set data with 2-dimensional vector as data,
java.util.Vector data = new java.util.Vector();
java.util.Vector row1Data = new
java.util.Vector();
row1Data.addElement("cell11");
row1Data.addElement("cell12");
row1Data.addElement("cell13");
data.addElement(row1Data);
java.util.Vector row2Data = new
java.util.Vector();
row2Data.addElement("cell21");
row2Data.addElement("cell22");
row2Data.addElement("cell23");
data.addElement(row2Data);
java.util.Vector row3Data = new
java.util.Vector();
row3Data.addElement("cell31");
row3Data.addElement("cell32");
row3Data.addElement("cell33");
data.addElement(row3Data);
awtTable.setData(data);
This sets 2-dimensional vector as data.
Ø To set 2-dimensional object array as data,
Object[][] data = new Object[][]
{
{"cell11",
"cell12", "cell13"},
{"cell21",
"cell22", "cell23"},
{"cell31",
"cell32", "cell33"}
};
awtTable.setData(data);
This sets the 2-dimensional object array as data.
ElegantJ AWTTable allow following paper sizes:
|
Paper Types |
Paper Types |
|
A2_ENVELOP_TYPE |
A4_TYPE |
|
A5_TYPE |
A6_CARD_TYPE |
|
B5_TYPE |
C6_ENVELOP_TYPE |
|
CUSTOM_TYPE |
DL_ENVELOP_TYPE |
|
EXECUTIVE_TYPE |
HAGAKI_CARD_TYPE |
|
INDEX_CARD_4x6_TYPE |
INDEX_CARD_5x8_TYPE |
|
LEGAL_TYPE |
LETTER_TYPE |
|
N010_ENVELOP_TYPE |
CUSTOM_TYPE |
Ø To set paper type,
awtTable.setPaperType(com.elegantj.awt.table.AWTTable.A4_TYPE);// sets paper type as A4
If paper type as set as CUSTOM_TYPE, then you need to set paper width and height explicitly using following methods,
awtTable.setPaperType(com.elegantj.awt.table.AWTTable.CUSTOM_TYPE);
awtTable.setPaperSize(10, 8); // sets paper width as 8 inch and height as 10 inch
Ø To retrieve paper width and paper height,
int paperWidth = awtTable.getPaperWidth(); // returns the paper width in inches
int paperHeight = awtTable.getPaperHeight(); // returns the paper height in inches
Ø To retrieve imageable paper width and height, imageable paper width and height are size of paper on to which printing can be done.
int imageablePaperWidth =
awtTable.getImageablePaperWidth();
int imageablePaperHeight =
awtTable.getImageablePaperHeight();
Ø To retrieve actual paper width and height, actual paper width and height are width and height of the paper in which left, right, top and bottom margins are not included.
int actualPaperWidth =
awtTable.getActualPaperWidth();
int actualPaperHeight =
awtTable.getActualPaperHeight();
Ø To set left, right, top and bottom margins,
printer.setLeftMargin(1); // margin in inches
printer.setRightMargin(1); // margin in inches
printer.setTopMargin(1); // margin in inches
printer.setBottomMargin(1); // margin in inches
printer.setTopMargin(1); // margin in inches
printer.setBottomMargin(1); // margin in inches
printer.setTopMargin(1); // margin in inches
printer.setBottomMargin(1); // margin in inches
Ø To set left, center, right header and footer,
printer.setLeftHeader("left header"); // sets left header
printer.setCenterHeader("center header"); // sets center header
printer.setRightHeader("right header"); // sets right header
printer.setLeftFooter("left footer"); // sets left footer
printer.setCenterFooter("center footer"); // sets center footer
printer.setRightFooter("right footer"); // sets right footer
Note: You can use following string constants with header / footer
Ø Printer.CURRENT_DATE
Ø Printer.CURRENT_TIME
Ø Printer.PAGE_NO
Ø Printer.TOTAL_PAGES
Ø To set current date in header / footer,
setXXXYYY("Date:
"+com.elegantj.util.printer.Printer.CURRENT_DATE);
Ø To set current time in header/footer,
setXXXYYY("Date:
"+com.elegantj.util.printer.Printer.CURRENT_TIME);
Ø To set page no. in header/footer,
setXXXYYY("Page No.:
"+com.elegantj.util.printer.Printer.PAGE_NO);
Ø To set page no./total no. of pages,
setXXXYYY("Page: " +
com.elegantj.util.printer.Printer.PAGE_NO + " of "
+com.elegantj.util.printer.Printer.TOTAL_PAGES);
where XXX is Left/Right and YYY = Header/Footer
Ø To set page orientation,
Orientation can be set as Printer.LANDSCAPE for landscape and Printer.PORTRAIT for portrait.
awtTable.setPageOrientation(com.elegantj.awt.table.AWTTable.LANDSCAPE); // sets orientation as landscape
Ø To set number of copies,
awtTable.setNoOfCopies(5); // sets number of copies as 5. This will print 5 copies of each page
Ø To show a line below header and line above footer,
awtTable.setShowLineBelowHeader(true); // which shows a line below header
awtTable.setShowLineAboveFooter(true); // which shows a line above footer
ElegantJ AWTTable provides ready-to-use Page Setup dialog using which user can,
Ø change the left, right, top and bottom margins
Ø set the left, center, right header and footer
Ø set the paper type and paper size
Ø set the page orientation
Ø set no. of copies
Ø turn on/off the line below header and above footer
Ø To open the page setup dialog,
awtTable.pageSetup(); // displays the page setup dialog
or
awtTable.pageSetup(jFrame); // displays the page setup dialog with jFrame as parent
ElegantJ AWTTable provides much needed preview feature. It supports Zoom In, Zoom Out and easy navigation through all the pages.
Ø To open Print Preview dialog,
awtTable.preview(); // displays preview dialog
or
awtTable.preview(jFrame); // displays preview dialog with jFrame as parent
The Process of Printing
Ø To print all the pages
awtTable.print(); // prints all the pages
Pages are spooled before they are printed. Spooling will take long time if number of pages is more. You can control spool size by printing books individually (at a time). Next two points focuses on how you can control spool size.
Ø Print book individually, and
Ø Book size
Ø Print book individually
Printing of large number of pages takes long time for spooling followed by printing. To reduce delay in printing due to this, it is suggested to print books individually.
Set value of this property to True to stop spooling of entire print job. As a result of this, computer spools a pre-set number of pages (user configurable) and prints it. It print books individually. Each book contains number of pages set as value of BookSize property.
printer.setPrintBookIndividually(true);
Ø Book Size
If PrintBookIndividually property is set to true, then value set in BookSize property is considered for spooling. This way a large print job is divided into smaller print jobs known as individual books.
printer.setPrintBookIndividually(true);
printer.setBookSize(5); // does not spool all the pages, considers 5 pages per book
e.g.
Divide a 200 page print job in 20 smaller jobs of 10 pages each. This will enable JAVA application to print this big job smoothly without any spooling delays or network congestions.
Printing large number of pages takes long time for spooling followed by printing. To stop spooling, print books individually.
If the value of this property is true, then printer does not spool all the pages before starting to print. It prints books individually. Each book contains number of pages set as value of BookSize property.
1. print()
This method prints all pages.
printer.print();
2. print(int pageIndex)
This method prints specified page with pageIndex, pageIndex is zero based page index. This method starts printing without showing print dialog.
printer.print(pageIndex)
3. print(int startPageIndex, int endPageIndex)
This method prints pages range specified with startPageIndex and endPageIndex, both page indexes are inclusive. This method starts printing without showing print dialog.
printer.print(startPageIndex,
endPageIndex);
4. print(FileInputStream fis)
This method prints content of FileInputStream on printer target port.
printer.print(fileInputStream);
5. print(FileInputStream fis, String port)
This method prints content of FileInputStream, on specified printer target port.
printer.print(fileInputStream, port);
6. print(byte[] bytes)
This method prints content of bytes array on printer target port.
printer.print(bytes);
7. print(byte[] bytes, String port)
This method prints content of bytes array, on specified printer target port.
printer.print(bytes, port);
ElegantJ Printer provides the following event.
PrinterEvent which is invoked when the printing is going on.
|
Listener Name |
TableCellEditListener |
|
Event that it receives |
TableCellEditEvent |
|
When it fires |
Just before editing is started and after editing is completed. |
|
Listener Name |
TableCellResizeListener |
|
Event that it receives |
TableCellResizeEvent |
|
When it fires |
Any row or column of a table is resized. |
|
Listener Name |
TableColumnsAddedListener |
|
Event that it receives |
TableColumnsAddedEvent |
|
When it fires |
One or more columns are added to the table. |
|
Listener Name |
TableColumnsRemovedListener |
|
Event that it receives |
TableColumnsRemovedEvent |
|
When it fires |
One or more columns are removed from the table. |
|
Listener Name |
TableRowsAddedListener |
|
Event that it receives |
TableRowsAddedEvent |
|
When it fires |
One or more rows are added to the table |
|
Listener Name |
TableRowsRemovedListener |
|
Event that it receives |
TableRowsRemovedEvent |
|
When it fires |
One or more rows are removed from the table |
|
Listener Name |
TableSelectionListener |
|
Event that it receives |
TableSelectionEvent |
|
When it fires |
When selection is changed. |
|
Listener Name |
TableSortListener |
|
Event that it receives |
TableSortEvent |
|
When it fires |
Before sorting and after sorting is done through column header click. |
ElegantJ JFCTable can be created using any one of following classes -
Ø com.elegantj.jfc.table.JFCTable - to create an instance of JFCTable without JScrollPane.
Ø com.elegantj.jfc.table.JFCTablePanel - to create an instance of JFCTable with JScrollPane.
So, if you want to use JFCTable with JScrollPane then create instance of JFCTablePanel otherwise create instance of JFCTable. In this JFCTables programmers guide we have created JFCTablePanel's object throughout.
ElegantJ JFCTable can be created in following ways,
Ø To create JFCTable with 20 rows and 5 columns,
com.elegantj.jfc.table.JFCTablePanel jfcTablePanel = new com.elegantj.jfc.table.JFCTablePanel();
Ø To create an instance of JFCTable with specified table model,
javax.swing.table.DefaultTableModel tableModel =
s new javax.swing.table.DefaultTableModel(10, 5);
com.elegantj.jfc.table.JFCTablePanel jfcTablePanel =
new com.elegantj.jfc.table.JFCTablePanel(tableModel);
Ø To create an instance of JFCTable with 10 rows and 5 columns,
int rowCount = 10;
int columnCount = 5;
com.elegantj.jfc.table.JFCTablePanel jfcTablePanel =
new com.elegantj.jfc.table.JFCTablePanel(rowCount, columnCount);
Ø To create an instance of JFCTable with specified row data and column names,
Object[][] rowData = new Object[][]
{
{"cell11", "cell12", "cell13"},
{"cell21", "cell22", "cell23"},
{"cell31", "cell32", "cell33"}
};
Object[] columnNames = new Object[] {"column1", "column2", "column3"};
com.elegantj.jfc.table.JFCTablePanel jfcTablePanel = new com.elegantj.jfc.table.JFCTablePanel(rowData, columnNames);
Ø To create an instance of JFCtable with the specified row data and column names as vector,
java.util.Vector rowData = new java.util.Vector();
java.util.Vector row1Data = new java.util.Vector();
row1Data.addElement("cell11");
row1Data.addElement("cell12");
row1Data.addElement("cell13");
rowData.addElement(row1Data);
java.util.Vector row2Data = new java.util.Vector();
row2Data.addElement("cell21");
row2Data.addElement("cell22");
row2Data.addElement("cell23");
rowData.addElement(row2Data);
java.util.Vector row3Data = new java.util.Vector();
row3Data.addElement("cell31");
row3Data.addElement("cell32");
row3Data.addElement("cell33");
rowData.addElement(row3Data);
java.util.Vector columnNames = new java.util.Vector();
columnNames.addElement("column1");
columnNames.addElement("column2");
columnNames.addElement("column3");
com.elegantj.jfc.table.JFCTablePanel jfcTablePanel =
new com.elegantj.jfc.table.JFCTablePanel(rowData, columnNames);
JFCTable has following general formatting features -
Ø Font
Ø Background
Ø Foreground
Ø Visible
Ø Enabled
Ø Locale
Ø Cursor
Ø Bounds
Ø Lightweight
Ø Opaque
Ø ToolTipText
Ø DoubleBuffered
Ø Autoscrolls
Ø RequestFocusEnabled
Ø Border
Ø ManagingFocus
Ø To set Font,
jfcTablePanel.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12)); // sets fonts as Dialog, with style as plain, size 12
Ø To set Background,
jfcTablePanel.setBackground(java.awt.Color.cyan); // sets background color as cyan
Ø To set Foreground,
jfcTablePanel.setForeground(java.awt.Color.black); // sets foreground color as black
Ø To set Visibility,
jfcTablePanel.setVisible(true); // which sets visibility as true
Ø To set Enability,
jfcTablePanel.setEnabled(true); // sets enability as true
Ø To set Locale,
jfcTablePanel.setLocale(java.util.Locale.ENGLISH); // sets locale as English
Ø To set Cursor,
jfcTablePanel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); // sets cursor as hand cursor
Ø To set Bounds,
int x = 5;
int y = 5;
int width = 300;
int height = 200;
jfcTablePanel.setBounds(x, y, width, height); // sets bounds to x, y, width and height
Ø To set Lightweight,
jfcTablePanel.setLightweight(true); // sets Lightweight as true
Ø To set Opaque,
jfcTablePanel.setOpaque(true); // sets opaque as true
Ø To set Tooltip Text,
jfcTablePanel.setTooltipText("JFCTable"); // sets TooltipText as "JFCTable"
Ø To set DoubleBuffered,
jfcTablePanel.setDoubleBuffered(true); // enables double buffering
Ø To set AutoScrolls,
jfcTablePanel.setAutoScrolls(true); // sets auto scrolls as true
Ø To set RequestFocusEnabled,
jfcTablePanel.setRequestFocusEnabled(true); // sets request focus enabled as true
Ø To set Border,
javax.swing.Border lineBorder =
javax.swing.BorderFactory.createLineBorder(java.awt.Color.black);
jfcTablePanel.setBorder(lineBorder); // sets border as black colored line border
Ø To set ManagingFocus,
jfcTablePanel.setManagingFocus(true); // sets managing focus as true
ElegantJ JFCTables provides the following advanced look & feel,
Ø BackgroundNonSelectionColor
Ø BackgroundSelectionColor
Ø TextNonSelectionColor
Ø TextSelectionColor
Ø BorderSelectionColor
Ø FocusCellBackgroundColor
Ø FocusCellForegroundColor
Ø Icon
Ø Font
Ø CellRenderer
Ø CellEditor
Ø Editable
Ø To set default BackgroundNonSelectionColor for whole table,
jfcTablePanel.setDefaultBackgroundNonSelectionColor(java.awt.Color.cyan); // sets default background color as cyan for whole table
Ø To set default BackgroundSelectionColor for whole table,
jfcTablePanel.setDefaultBackgroundSelectionColor(java.awt.Color.blue); // sets default background color as blue for whole table
Ø To set default TextNonSelectionColor for whole table,
jfcTablePanel.setDefaultTextNonSelectionColor(java.awt.Color.black); // sets default text color as black for whole table
Ø To set default TextSelectionColor for whole table,
jfcTablePanel.setDefaultTextSelectionColor(java.awt.Color.yellow); // sets default text selection color as yellow for whole table
Ø To set default BorderSelectionColor for whole table,
jfcTablePanel.setDefaultBorderSelectionColor(java.awt.Color.red); // sets default border selection color to red for whole table
Ø To set default FocusCellBackgroundColor for whole table,
jfcTablePanel.setDefaultFocusCellBackgroundColor(java.awt.Color.red); // sets default focus cell background color as red for whole table
Ø To set default FocusCellForegroundColor for whole table,
jfcTablePanel.setDefaultFocusCellForegroundColor(java.awt.Color.blue); // sets default focus cell foreground color as blue for whole table
Ø To set default Font for whole table,
jfcTablePanel.setDefaultFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12)); // sets default font as dialog font for whole table
Ø To set default image icon for whole table,
javax.swing.ImageIcon imageIcon =
new
javax.swing.ImageIcon("c:/my_folder/image.jpg");
jfcTablePanel.setDefaultIcon(imageIcon); // sets default icon for whole table
Ø To set default icon path for whole table,
jfcTablePanel.setDefaultIconPath("c:/my_folder/image.jpg"); // sets default icon path for whole table
Ø To set default cell renderer for whole table,
Following cell renderers comes with the ElegantJ JFCTable beanary,
o Boolean cell renderer –
com.elegantj.jfc.common.renderers.BooleanRenderer
o Checkbox cell renderer –
com.elegantj.jfc.common.renderers.CheckboxRenderer
o Choice cell renderer –
com.elegantj.jfc.common.renderers.ChoiceRenderer
o Color cell renderer –
com.elegantj.jfc.common.renderers.ColorRenderer
o Date cell renderer –
com.elegantj.jfc.common.renderers.DateRenderer
o Default cell renderer –
com.elegantj.jfc.common.renderers.DefaultRenderer
o Icon cell renderer –
com.elegantj.jfc.common.renderers.IconRenderer
o MultiLine cell renderer –
com.elegantj.jfc.common.renderers.MultiLineRenderer
o MultiOption cell renderer –
com.elegantj.jfc.common.renderers.MultiOptionRenderer
o Number cell renderer –
com.elegantj.jfc.common.renderers.NumberRenderer
o Progress cell renderer –
com.elegantj.jfc.common.renderers.ProgressRenderer
o RadioButton cell renderer –
com.elegantj.jfc.common.renderers.RadioButtonRenderer
o Text cell renderer –
com.elegantj.jfc.common.renderers.TextRenderer
com.elegantj.jfc.common.renderers.CheckboxRenderer checkboxRenderer = new com.elegantj.jfc.common.renderers.CheckboxRenderer(); jfcTablePanel.setDefaultCellRenderer(checkboxRenderer); // sets the default renderer as checkbox for whole table
Ø To set default cell editor,
com.elegantj.jfc.common.editors.CheckboxEditor
checkboxEditor =
new
com.elegantj.jfc.common.editors.CheckboxEditor();
jfcTablePanel.setDefaultCellEditor(checkboxEditor); // sets default editor as checkbox for whole table
Ø To set default editibality,
jfcTablePanel.setDefaultEditable(new Boolean(false)); // sets whole table as not editable
JFCTable provides the following advanced formatting features to be set row and columns wise -
Ø BackgroundNonSelectionColor
Ø BackgroundSelectionColor
Ø TextNonSelectionColor
Ø TextSelectionColor
Ø BorderSelectionColor
Ø FocusCellBackgroundColor
Ø FocusCellForegroundColor
Ø Icon
Ø Font
Ø CellRenderer
Ø CellEditor
Ø Editable
Ø To set row / column wise BackgroundNonSelectionColor,
jfcTablePanel.setRowBackgroundNonSelectionColor(java.awt.Color.cyan, 0); // sets background non selection color as cyan for row at 0th index
jfcTablePanel.setColumnBackgroundNonSelectionColor(java.awt.Color.cyan, 0); // sets background non selection color as cyan for column at 0th index
Ø To set row / column wise BackgroundSelectionColor,
jfcTablePanel.setRowBackgroundSelectionColor(java.awt.Color.blue, 0); // sets background selection color as blue for row at 0th index
jfcTablePanel.setColumnBackgroundSelectionColor(java.awt.Color.blue, 0); // sets background selection color as blue for column at 0th index
Ø To set row / column wise TextNonSelectionColor,
jfcTablePanel.setRowTextNonSelectionColor(java.awt.Color.black, 0); // sets text non selection color as black for row at 0th index
jfcTablePanel.setColumnTextNonSelectionColor(java.awt.Color.black, 0); // sets text non selection color as black for column at 0th index
Ø To set row / column wise TextSelectionColor
jfcTablePanel.setRowTextSelectionColor(java.awt.Color.yellow, 0); // sets text selection color as yellow for row at 0th index
jfcTablePanel.setColumnTextSelectionColor(java.awt.Color.yellow, 0); // sets text selection color as yellow for column at 0th index
Ø To set row / column wise BorderSelectionColor
jfcTablePanel.setRowBorderSelectionColor(java.awt.Color.red, 0); // sets border selection color as red for row at 0th index
jfcTablePanel.setColumnBorderSelectionColor(java.awt.Color.red, 0); // sets border selection color as red for column at 0th index
Ø To set row / column wise FocusCellBackgroundColor
jfcTablePanel.setRowFocusCellBackgroundColor(java.awt.Color.red, 0); // sets focus cell background color as red for row at 0th index
jfcTablePanel.setColumnFocusCellBackgroundColor(java.awt.Color.red, 0); // sets focus cell background color as red for column at 0th index
Ø To set row / column wise FocusCellForegroundColor
jfcTablePanel.setRowFocusCellForegroundColor(java.awt.Color.red, 0); // sets focus cell foreground color as red for row at 0th index
jfcTablePanel.setColumnFocusCellForegroundColor(java.awt.Color.red, 0); // sets focus cell foreground color as red for column at 0th index
Ø To set row/column wise Font
jfcTablePanel.setRowFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12), 0); // sets font as dialog, plain, 12 size for row at 0th index
jfcTablePanel.setColumnFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12), 0); // sets font as dialog, plain, 12 size for column at 0th index
Ø To set row / column wise icon
javax.swing.ImageIcon imageIcon = new
javax.swing.ImageIcon("c:/my_folder/image.jpg");
jfcTablePanel.setRowIcon(imageIcon, 0); // sets icon for row at 0th index
jfcTablePanel.setColumnIcon(imageIcon, 0); // sets icon for column at 0th index
Ø To set row / column wise icon path
jfcTablePanel.setRowIconPath("c:/my_folder/image.jpg", 0); // sets icon path for row at 0th index
jfcTablePanel.setColumnIconPath("c:/my_folder/image.jpg", 0); // sets icon path for column at 0th index
Ø To set row / column wise cell renderer
Following cell renderers comes with the ElegantJ JFCTable beanary,
o Boolean cell renderer –
com.elegantj.jfc.common.renderers.BooleanRenderer
o Checkbox cell renderer –
com.elegantj.jfc.common.renderers.CheckboxRenderer
o Choice cell renderer –
com.elegantj.jfc.common.renderers.ChoiceRenderer
o Color cell renderer –
com.elegantj.jfc.common.renderers.ColorRenderer
o Date cell renderer –
com.elegantj.jfc.common.renderers.DateRenderer
o Default cell renderer –
com.elegantj.jfc.common.renderers.DefaultRenderer
o Icon cell renderer –
com.elegantj.jfc.common.renderers.IconRenderer
o MultiLine cell renderer –
com.elegantj.jfc.common.renderers.MultiLineRenderer
o MultiOption cell renderer –
com.elegantj.jfc.common.renderers.MultiOptionRenderer
o Number cell renderer –
com.elegantj.jfc.common.renderers.NumberRenderer
o Progress cell renderer –
com.elegantj.jfc.common.renderers.ProgressRenderer
o RadioButton cell renderer –
com.elegantj.jfc.common.renderers.RadioButtonRenderer
o Text cell renderer –
com.elegantj.jfc.common.renderers.TextRenderer
com.elegantj.jfc.common.renderers.CheckboxRenderer
checkboxRenderer = new com.elegantj.jfc.common.renderers.CheckboxRenderer();
jfcTablePanel.setRowCellRenderer(checkboxRenderer, 0); // sets checkbox as a cell renderer for row at 0th index
jfcTablePanel.setColumnCellRenderer(checkboxRenderer, 0); // sets checkbox as a cell renderer for column at 0th index
Ø To set row/column wise cell editor
Following cell editors come with the ElegantJ JFCTable benary,
o Boolean cell editor –
com.elegantj.jfc.common.editors.BooleanEditor
o Checkbox cell editor –
com.elegantj.jfc.common.editors.CheckboxEditor
o Choice cell editor - com.elegantj.jfc.common.editors.ChoiceEditor
o Color cell editor - com.elegantj.jfc.common.editors.ColorEditor
o Date cell editor - com.elegantj.jfc.common.editors.DateEditor
o Default cell editor - com.elegantj.jfc.common.editors.DefaultEditor
o Icon cell editor - com.elegantj.jfc.common.editors.IconEditor
o MultiLine cell editor –
com.elegantj.jfc.common.editors.MultiLineEditor
o MultiOption cell editor –
com.elegantj.jfc.common.editors.MultiOptionEditor
o Number cell editor –
com.elegantj.jfc.common.editors.NumberEditor
o RadioButton cell editor –
com.elegantj.jfc.common.editors.RadioButtonEditor
o Slider cell editor - com.elegantj.jfc.common.editors.SliderEditor
com.elegantj.jfc.common.editors.CheckboxEditor
checkboxEditor =
new
com.elegantj.jfc.common.editors.CheckboxEditor();
jfcTablePanel.setRowCellEditor(checkboxEditor); // sets checkbox as a cell editor for row at 0th index
jfcTablePanel.setColumnCellEditor(checkboxEditor); // sets checkbox as a cell editor for column at 0th index
Ø To set row/column wise editibality
jfcTablePanel.setRowEditable(new Boolean(false), 0); // makes row as not editable for row at 0th index
jfcTablePanel.setColumnEditable(new Boolean(false), 0); // makes column as not editable for column at 0th index
Note: All above row/column wise attributes prefers row wise attributes over column wise attributes. That is, if one has set above attributes for the 1st row and also for 1st column, then 1st cell of the table (occupied by 1st row and 1st column) will be rendered with 1st rows attributes.
With JFCTable, you can set following properties for header -
Ø SortColumnOnClick
Ø AdjustColumnOnClick
Ø ColumnReorderingAllowed
Ø ColumnResizingAllowed
Ø ColumnHeaderBackground
Ø ColumnHeaderForeground
Ø ColumnHeaderFont
Ø ColumnHeaderHeight
Ø ColumnHeaderVisible
Ø To set sort column on click.
jfcTablePanel.setSortColumnOnClick(true); // enables sorting of column on column click
Ø To set adjust column on click,
jfcTablePanel.setAdjustColumnOnClick(true); // enables adjusting of column on column click
Ø To set column reordering property,
jfcTablePanel.setColumnReorderingAllowed(false); // disables reordering of columns
Ø To enable / disable column resizing,
jfcTablePanel.setColumnResizingAllowed(false); // disables column resizing
Ø To set column header background,
jfcTablePanel.setColumnHeaderBackground(java.awt.Color.blue); // sets column header background color as blue
Ø To set column header foreground,
jfcTablePanel.setColumnHeaderForeground(java.awt.Color.black); // sets column header foreground color as black
Ø To set column header font,
jfcTablePanel.setColumnHeaderFont(new java.awt.Font("Dialog", Font.BOLD, 12)); // sets column header font as dialog, bold, 12 size.
Ø To set column header height,
jfcTablePanel.setColumnHeaderHeight(30); // sets column header height as 30 pixels
Ø To set visibility of column header,
jfcTablePanel.setColumnHeaderVisible(false); // sets the column header as invisible
With JFCTable, you can set following properties for header -
Ø AdjustRowOnClick
Ø RowResizingAllowed
Ø RowHeaderBackground
Ø RowHeaderForeground
Ø RowHeaderFont
Ø RowHeaderWidth
Ø RowHeaderVisible
Ø To set adjust row on click feature,
jfcTablePanel.setAdjustRowOnClick(true); // enables adjusting of row on row-click
Ø To enable/disable row resizing,
jfcTablePanel.setRowResizingAllowed(false); // disables row resizing
Ø To set row header background,
jfcTablePanel.setRowHeaderBackground(java.awt.Color.blue); // sets row header background color as blue
Ø To set row header foreground,
jfcTablePanel.setRowHeaderForeground(java.awt.Color.black); // sets row header foreground color as black
Ø To set row header font,
jfcTablePanel.setRowHeaderFont(new java.awt.Font("Dialog", Font.BOLD, 12)); // sets row header font to dialog, bold, 12 size
Ø To set row header height,
jfcTablePanel.setRowHeaderHeight(30); // sets row header height as 30 pixels
Ø To set visibility of row header,
jfcTablePanel.setRowHeaderVisible(false); // makes row header invisible
With JFCTable, you can apply any cell renderer / cell editor to whole table as well as to selected rows (s) / column(s).
The basic renderers supplied with this package are listed below,
Ø BooleanRenderer
Ø CheckboxRenderer
Ø ChoiceRenderer
Ø ColorRenderer
Ø DateRenderer
Ø DefaultRenderer
Ø IconRenderer
Ø MultiLineRenderer
Ø MultiOptionRenderer
Ø NumberRenderer
Ø ProgressRenderer
Ø RadioButtonRenderer
Ø TextRenderer
Here is a list of basic editors shipped with Bean -
Ø BooleanEditor
Ø CheckboxEditor
Ø ChoiceEditor
Ø ColorEditor
Ø DateEditor
Ø DefaultEditor
Ø IconEditor
Ø MultiLineEditor
Ø MultiOptionEditor
Ø NumberEditor
Ø RadioButtonEditor
Ø SliderEditor
Ø TextEditor
Ø To set cell renderer for whole table,
com.elegantj.jfc.common.renderers.CheckboxRenderer
checkboxRenderer = new com.elegantj.jfc.common.renderers.CheckboxRenderer();
jfcTablePanel.setDefaultCellRenderer(checkboxRenderer);
// This sets cell renderer as checkbox for whole table
Ø To set cell renderer at row level,
com.elegantj.jfc.common.renderers.CheckboxRenderer
checkboxRenderer = new com.elegantj.jfc.common.renderers.CheckboxRenderer();
jfcTablePanel.setRowCellRenderer(checkboxRenderer,
0);
// This sets cell renderer as checkbox for row at 0th index
Ø To set cell renderer at column level,
com.elegantj.jfc.common.renderers.CheckboxRenderer
checkboxRenderer = new com.elegantj.jfc.common.renderers.CheckboxRenderer();
jfcTablePanel.setColumnCellRenderer(checkboxRenderer,
0);
// This sets cell renderer as checkbox for column at 0th index
Ø To set cell editor for whole table,
com.elegantj.jfc.common.editors.CheckboxEditor
checkboxEditor =
new
com.elegantj.jfc.common.editors.CheckboxEditor();
jfcTablePanel.setDefaultCellEditor(checkboxEditor,
0);
// This sets cell editor as checkbox for whole table
Ø To set cell editor at row level,
com.elegantj.jfc.common.editors.CheckboxEditor
checkboxEditor =
new
com.elegantj.jfc.common.editors.CheckboxEditor();
jfcTablePanel.setRowCellEditor(checkboxEditor,
0);
// This sets cell editor as checkbox for row at 0th index
Ø To set cell editor at column level,
com.elegantj.jfc.common.editors.CheckboxEditor
checkboxEditor =
new
com.elegantj.jfc.common.editors.CheckboxEditor();
jfcTablePanel.setColumnCellEditor(checkboxEditor,
0);
// This sets cell editor as checkbox for column at 0th index
ElegantJ JFCTable offers following grid attributes -
Ø Grid color
Ø Show Grid
Ø Show horizontal lines
Ø Show vertical lines
Ø To set grid color,
java.awt.Color gridColor =
java.awt.Color.black;
jfcTablePanel.setGridColor(gridColor); // This sets grid color as black.
Ø To set visibility of grid,
jfcTablePanel.setShowGrid(false); // makes the grid invisible
Ø To set the visibility of horizontal grid lines,
jfcTablePanel.setShowHorizontalLines(false); // makes the horizontal grid invisible
Ø To set the visibility of the vertical grid lines,
jfcTablePanel.setShowVerticalLines(false); // makes vertical grid lines invisible
JFCTable provides the following methods to set the row heights,
Ø To set the row height for all the rows,
jfcTablePanel.setRowHeight(20);
which sets the row height to 20.
Ø To set the row height for the specified row,
jfcTablePanel.setRowHeight(0, 20);
which sets the row height for the 0th row to 20.
JFCTable provides the following method to set row margin.
Ø To set the row margin,
jfcTablePanel.setRowMargin(5);
which sets the row margin to 5.
JFCTable provides following methods to set column widths
Ø To set column width for specified column,
jfcTablePanel.setColumnWidth(0, 80); // sets column width for column 0 as 80 pixels
Ø To set column margin,
jfcTablePanel.setColumnMargin(5); // sets the column margin as 5 pixels
You can have three type of selection
Ø javax.swing.ListSelectionModel.SINGLE_SELECTION - only one path can be selected at a time.
Ø javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION - only contiguous paths can be selected.
Ø javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION - any path can be selected.
Ø To set selection mode,
jfcTablePanel.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); // sets selection to single selection
Ø To select a row,
jfcTablePanel.setSelectedRow(0); // selects row at 0th index
Ø To select more than one rows,
jfcTablePanel.setSelectedRows(new int[]{0, 1, 2}); // sets row at 0th, 1st and 2nd index
Ø To select column,
jfcTablePanel.setSelectedColumn(0); // sets column at 0th index
Ø To select columns,
jfcTablePanel.setSelectedColumns(new int[]{0, 1, 2}); // selects columns at 0th, 1st and 2nd index
Ø To remove row selection interval,
jfcTablePanel.removeRowSelectionInterval(0, 2); // removes selection on rows at 0th, 1st and 2nd index
Ø To remove column selection interval,
jfcTablePanel.removeColumnSelectionInterval(0, 2); // removes selection on columns at 0th, 1st and 2nd index
Ø To clear selection of the whole table,
jfcTablePanel.clearSelection(); // clears the selection of whole table.
Ø To set default editability,
jfcTablePanel.setDefaultEditable(true); // allows to edit whole JFCTable
Ø To set row wise editability,
jfcTablePanel.setRowEditable(new Boolean(false), 0); // sets row 0 as not editable
Ø To set column editability,
jfcTablePanel.setColumnEditable(new Boolean(false), 0); // sets coumn 0 as not editable
Ø To start editing at the specified table cell,
com.elegantj.jfc.table.TableCell tableCell
=
new com.elegantj.jfc.table.TableCell(2, 2);
jfcTablePanel.editTableCell(tableCell);
This starts editing at the cell represented by 2nd row and 2nd column.
JFCTable provides the following methods to configure data to the JFCTable,
Ø To set data,
java.util.Vector data = new
java.util.Vector();
java.util.Vector row1Data = new
java.util.Vector();
row1Data.addElement("cell11");
row1Data.addElement("cell12");
row1Data.addElement("cell13");
data.addElement(row1Data);
java.util.Vector row2Data = new java.util.Vector();
row2Data.addElement("cell21");
row2Data.addElement("cell22");
row2Data.addElement("cell23");
data.addElement(row2Data);
java.util.Vector row3Data = new
java.util.Vector();
row3Data.addElement("cell31");
row3Data.addElement("cell32");
row3Data.addElement("cell33");
data.addElement(row3Data);
jfcTablePanel.setData(data);
which sets the 2-dimensional vector as a data.
Ø To set value at the specified row and column,
jfcTablePanel.setValueAt("Cell 1, 1", 1, 1); // sets value at cell specified by row 1 and column 1.
ElegantJ JFCTable provides following auto- resizing modes,
JFCTable considers the following modes when a column of table is being resized:
Ø com.elegantj.jfc.table.JFCTablePanel.AUTO_RESIZE_ALL_COLUMNS - Spared the delta amongst all the columns in the JFCTable, including the one that is being adjusted.
Ø com.elegantj.jfc.table.JFCTablePanel.AUTO_RESIZE_LAST_COLUMN - Automatically adjust the size of last column only, If the last column to the appropriate limit and make no further adjustments.
Ø com.elegantj.jfc.table.JFCTablePanel.AUTO_RESIZE_NEXT_COLUMN - Use just the column after the resizing column, This results in the "boundary" or divider between adjacent cells being independently adjustable.
Ø com.elegantj.jfc.table.JFCTablePanel.AUTO_RESIZE_SQBSEQUENT_COLUMN - Use all columns after the one being adjusted to absorb the changes. This is the default behavior
Ø com.elegantj.jfc.table.JFCTablePanel.AUTO_RESIZE_OFF - Don't automatically adjust the column's widths at all.
Ø To set auto resize mode,
jfcTablePanel.setAutoResizeMode(com.elegantj.jfc.table.JFCTablePanel.AUTO_RESIZE_ALL_COLUMNS);
This sets the auto resize mode to auto resize all columns.
Here is a list of key strokes available (for carrying out operations) for use on a cell of JFCTable -
Ø INSERT - for inserting row on insert key.
Ø DELETE - for deleting row on delete key.
Ø ENTER - for adding row on enter key at the last row position.
Ø To enable inserting of row using Insert key,
jfcTablePanel.setInsertRowOnInsertKey(true);
Ø To enable deleting of row using Delete key,
jfcTablePanel.setDeleteRowOnDeleteKey(true);
Ø To enable adding a row at the end of table using Enter key,
jfcTablePanel.setAddRowOnEnterKey(true);
This enables adding row on enter key, it works on last row only.
JFCTable provides a ready to use popup menu, having following functionalities -
Ø Add row / column
Ø Insert row / column
Ø Remove row / column
Ø Edit cell
Ø Sort (ascending / descending) column
All the above popup menu operations take place on selected row / column / cell.
Ø To set visibility of the popup menu,
jfcTablePanel.setPopupVisible(true);
This allows to open the popup menu on right-click.
Ø To set search panel's visibility,
jfcTablePanel.setSearchPanelVisible(false); // makes search panel invisible
Ø To set the search panel background,
jfcTablePanel.setSearchPanelBackground(java.awt.Color.gray); // sets search panel background as gray
Ø To set the search panel foreground,
jfcTablePanel.setSearchPanelForeground(java.awt.Color.black); // sets search panel foreground as black
Ø To set search panel font,
jfcTablePanel.setSearchPanelFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 12)); // sets search panel font as dialog, style as bold and size as 12
Ø To set search panel placement,
Possible values for the search panel placement are,
- javax.swing.SwingConstants.TOP
- javax.swing.SwingConstants.LEFT
- javax.swing.SwingConstants.BOTTOM
- javax.swing.SwingConstants.RIGHT
Ø To set search panel placement,
jfcTablePanel.setSearchPanelPlacement(com.elegantj.jfc.table.javax.swing.SwingConstants.TOP);
This places search panel at top.
Search Progress Options
|
Search Progress from |
Options for search Progress |
|
First cell |
com.elegantj.jfc.table.JFCTablePanel. SEARCH_FROM_FIRST_CELL |
|
Last cell |
com.elegantj.jfc.table.JFCTablePanel. SEARCH_FROM_LAST_CELL |
|
Selected cell upwards |
com.elegantj.jfc.table.JFCTablePanel. SEARCH_FROM_SELECTED_CELL_TO_UP |
|
Selected cell downwards |
com.elegantj.jfc.table.JFCTablePanel. SEARCH_FROM_SELECTED_CELL_TO_DOWN |
Comparison Options
|
Comparison requirement |
Option for comparison |
|
Search cell for value that starts with given search string |
com.elegantj.jfc.table.JFCTablePanel. COMPARE_STARTS_WITH |
|
Search cell for value that ends with given search string |
com.elegantj.jfc.table.JFCTablePanel. COMPARE_ENDS_WITH |
|
Search cell for value or its part equals given search string |
com.elegantj.jfc.table.JFCTablePanel. COMPARE_CONTAINS |
|
Search cell for value for given string for exact match |
com.elegantj.jfc.table.JFCTablePanel. COMPARE_EQUALS |
Ø To carry out a case insensitive search on table cell with specified cell string, column index and comparison mode,
String searchString = "search
string";
int searchOnColumn = 1;
int compareMode =
com.elegantj.jfc.table.JFCTablePanel.COMPARE_STARTS_WITH;
boolean isCaseSensitive = false;
com.elegantj.jfc.table.TableCell searchedTableCell
= jfcTablePanel.searchTableCell(searchString, searchOnColumn, compareMode,
isCaseSensitive);
This carries out a case insensitive search on column at index 1 with starts with compare mode, If search string found then it returns TableCell which contains row and column indexes where search string found.
Ø To carry out a case insensitive search on table cell with the specified cell string, column index and search mode and comparison mode,
String searchString = "search
string";
int searchOnColumn = 1;
int searchMode =
com.elegantj.jfc.table.JFCTablePanel.SEARCH_FROM_FIRST_CELL;
int compareMode =
com.elegantj.jfc.table.JFCTablePanel.COMPARE_STARTS_WITH;
boolean isCaseSensitive = false;
com.elegantj.jfc.table.TableCell
searchedTableCell =
jfcTablePanel.searchTableCell(searchString,
searchOnColumn, searchMode, compareMode, isCaseSensitive);
This carries out a case insensitive search on column at index 1 from first cell with starts with compare mode, If search string found then it returns TableCell which contains row and column indexes where search string found.
Ø To search table cell with the specified cell string, on multiple columns, comparison mode and case sensitivity,
String searchString = "search
string";
int searchOnColumns = new int[]{1, 2, 3};
int compareMode =
com.elegantj.jfc.table.JFCTablePanel.COMPARE_STARTS_WITH;
boolean isCaseSensitive = true;
com.elegantj.jfc.table.TableCell
searchedTableCell =
jfcTablePanel.searchTableCell(searchString,
searchOnColumns, compareMode, isCaseSensitive);
This carries out a case sensitive search on columns at indexes 1st, 2nd and 3rd with starts with compare mode, If search string found then it returns TableCell which contains row and column indexes where search string found.
Ø To search table cell with the specified cell string on multiple columns, search mode, comparison mode and case sensitivity,
String searchString = "search
string";
int searchOnColumns = new int[]{1, 2, 3};
int searchMode =
com.elegantj.jfc.table.JFCTablePanel.SEARCH_FROM_FIRST_CELL;
int compareMode =
com.elegantj.jfc.table.JFCTablePanel.COMPARE_STARTS_WITH;
boolean isCaseSensitive = false;
com.elegantj.jfc.table.TableCell
searchedTableCell =
jfcTablePanel.searchTableCell(searchString,
searchOnColumns, searchMode, compareMode, isCaseSensitive);
This carries out case sensitive search on columns at index 1, 2 and 3 from first cell with starts with compare mode, If search string found then it returns TableCell which contains row and column indexes where search string found.
Ø To search table cell with the specified value,
Object searchValue = "search
object";
com.elegantj.jfc.table.TableCell
searchedTableCell = jfcTablePanel.searchTableCell(searchValue);
This searches entire table with search value, If search string found then it returns TableCell which contains row and column indexes where search string found.
Ø To search table cell with the specified value and column index,
Object searchValue = "search
object";
int columnIndex = 1;
com.elegantj.jfc.table.TableCell searchedTableCell
= jfcTablePanel.searchTableCell(searchValue, columnIndex);
This searches column at index 1 with search value, If search string found then it returns TableCell which contains row and column index where search string found.
Ø To search table cell with the specified value and column indexes,
Object serachValue = "search
object";
int columnIndexes[] = new int[]{1, 2, 3};
com.elegantj.jfc.table.TableCell
searchedTableCell = jfcTablePanel.searchTableCell(searchValue, columnIndexes);
This searches for search value on columns at indexes 1st, 2nd and 3rd, If search string found then it returns TableCell which contains row and column indexes where search string found.
Ø To sort specified column,
int columnIndex = 1;
jfcTablePanel.sortColumn(columnIndex);
This sorts column at index 1 in ascending-descending-ascending-descending manner. That is, on 1st call, it sorts in ascending order on 2nd time in descending order and as on in this order.
Ø To sort specified column in ascending or descending order,
int columnIndex = 1;
boolean sortingOrder = true; // i.e.
ascending
jfcTablePanel.sortColumn(columnIndex,
sortingOrder);
This sorts column at index 1 in ascending order.
Ø To sort multiple columns,
int columnIndexes[] = new int[]{1, 2, 3};
jfcTablePanel.sortColumns(columnIndexes);
This sorts column at index 1, 2 and 3 in ascending-descending-ascending-descending order. That is, on 1st call, it sorts in ascending order. On 2nd call, in descending order and likewise.
Ø To sort multiple columns with specified sorting order,
int columnIndexes[] = new int[]{1, 2, 3};
boolean sortingOrders[] = new
boolean[]{true, false, true};
jfcTablePanel.sortColumns(columnIndexes,
sortingOrders);
This sorts column 1 in ascending order, column 2 in descending and column 3 in ascending order.
Product and Support Information:
Ø You can find more information about ElegantJ Tables and its features on www.ElegantJBeans.com.
Ø Forward your support related mails to support@ElegantJBeans.com.
Ø Forward your sales related mails to sales@ElegantJBeans.com.
Feedback and Suggestions:
Ø We will be pleased to get your feedback as well as suggestions about our product.
Ø Forward any feedback or suggestions related mails to support@ElegantJBeans.com.