2009年2月10日
JComponentPack 是一個(gè)基于Java Swing的GUI類庫(kù),一系列可視化的JavaBeans集合,它基于Swing的MVC架構(gòu),是100%的純Java類庫(kù),它包括20多個(gè)Swing 所沒有的控件,如EXCEL風(fēng)格Java的電子表格控件,讀取數(shù)據(jù)庫(kù)表的Java表格控件,日歷控件,類似資源管理器的列表控件,向?qū)Э蚣艿鹊龋@些 JavaBeans可以直接拖動(dòng)到您的圖形用戶界面,它可提高您的工作效率,加快您的項(xiàng)目開發(fā)過(guò)程。
功能列表
· JBean應(yīng)用程序框架
JBean應(yīng)用程序框架提供了一個(gè)標(biāo)準(zhǔn)的Swing應(yīng)用程序框架,它支持從屬性文件創(chuàng)建Actions,創(chuàng)建和動(dòng)態(tài)顯示菜單,也支持創(chuàng)建單選按鈕,多選按鈕,能動(dòng)態(tài)改變按鈕狀態(tài)。它提供了一個(gè)資源管理類,能夠從定義好的資源文件裝載小圖標(biāo),菜單和按鈕的資源。
JBean應(yīng)用程序框架包含了一些常用的標(biāo)準(zhǔn)控件,包括打印和打印預(yù)覽控件,狀態(tài)欄控件,登陸對(duì)話框,反饋對(duì)話框,外觀改變對(duì)話框等。
JBean應(yīng)用程序框架包含了一些常用的單元格繪制和編輯器,它們支持通用的數(shù)據(jù)類型,包括數(shù)字,日期,文件,圖表,顏色等類型。這些單元格繪制和編輯器也提供了不同的控件支持,包括復(fù)選框,下拉框等。
· JComponentSet控件集
JComponentSet是一個(gè)Java
swing控件集,包括JWizardPane,
JListView, Layout Suite (CellLayout, BoxLayout2, CardLayout2, GridLayout2), JDirChooser,
JCalendar, JFontChooser, JLinkButton, JSidePane, JSideBar, JImageViewer, XTree,
XCheckBox, JCardPane, JGridPane等一系列控件.
· 圖形控件
提供了常見的圖形, 2D圖形和3D圖形.
· 圖表控件
支持3種不同的圖表類型, 分別是餅形圖,條形圖和線形圖.
· 核心公式框架
核心公式框架定義了一個(gè)通用的公式框架,包括函數(shù)和公式定義,公式解析器等接口。
· JDataGrid核心控件
· 普通文件格式的輸入和輸出
支持輸入和輸出多種文件格式,包括csv, html, txt.
· JDataGrid電子表格控件
JDataGrid電子表格控件是了一個(gè)Java
swing 電子表格控件,提供了基本的功能,如撤銷和重做,合并單元格,拼寫檢查,Excel文件的輸入和輸出,打印和打印預(yù)覽等,也包括了復(fù)雜的高級(jí)功能.
· 電子表格公式
支持許多函數(shù),例如邏輯函數(shù), 日期函數(shù), 數(shù)學(xué)計(jì)算函數(shù), 文本函數(shù), 單元格函數(shù), 和部分的統(tǒng)計(jì)函數(shù).
· 高級(jí)文件格式的輸入和輸出
支持輸入和輸出多種文件格式,包括Excel xls, Excel xml, PDF等.
· JDataGrid電子表格JavaFX控件
最新的JDataGrid電子表格控件支持JavaFX平臺(tái),新添加了JavaFX控件"DataGrid"和"DataGridBean",您可以在JavaFX腳本中直接使用這些控件,這些JavaFX控件直接支持最新的JDataGrid電子表格服務(wù)器端控件。
· JDataGrid電子表格JavaEE服務(wù)器端控件
最新的JDataGrid電子表格服務(wù)器端控件能部署在JavaEE應(yīng)用服務(wù)器上,JDataGrid小程序直接支持最新的服務(wù)器端控件,您可以通過(guò)簡(jiǎn)單的設(shè)置,設(shè)置一個(gè)服務(wù)器端控件的URL,就能讀取,保存,下載各種不同格式的電子表格文件,所有的配置在服務(wù)器端完成。
· JDataGrid數(shù)據(jù)庫(kù)控件
JDataGrid數(shù)據(jù)庫(kù)控件是一個(gè)能夠直接對(duì)數(shù)據(jù)庫(kù)操作的表格,基于標(biāo)準(zhǔn)的JDBC技術(shù),能夠直接操作ResultSet和RowSet,并提供如打印和打印預(yù)覽,多種格式的文件輸入和輸出的功能.
摘要: 新功能介紹:
3.0版本添加了最新的JDataGrid電子表格服務(wù)器端控件,JDataGrid小程序直接支持最新的服務(wù)器端控件,您可以通過(guò)簡(jiǎn)單的設(shè)置,設(shè)置一個(gè)服務(wù)器端控件的URL,就能讀取,保存,下載各種不同格式的電子表格文件, 所有的配置在服務(wù)器端完成。
3.0版本添加了JDataGrid JavaFX 控件"DataGrid"和"DataGridBean",您可以在JavaFX腳本中直接調(diào)用 這些控件,這些JavaFX控件直接支持最新的JDataGrid電子表格服務(wù)器端控件。
閱讀全文
JCalendar new features in JComponentPack
- New property to control the action click count
- New client property to control the "today” button action behavior
- JCalendar works with AComboBox and add new calendar popup icon.
1. New property to control the action click count
JCalendar provides new property named “actionClickCount” since
JComponentPack 1.1.0, use this property, you can set the mouse click count to fire the action event, JCalendar adds the following methods:
JCalendar.getActionClickCount();
JCalendar.setActionClickCount(int);
2. New client property to control the "today” button action behavior
With this new client property “JCalendar.todayButtonFireActionEventEnabled” since
JComponentPack 1.1.0, the JCalendar can fire the action event when the today button clicked.
The above new features is very important when JCalendar working with
the AComboBox, the the popup JCalendar make visible, by using the above
property, the popup can hidden when use click a "today” button or
select a specified day.
3. JCalendar works with AComboBox and add new calendar popup icon.
When AComBoBox set a Date value , the popup icon automatically became a calendar icon, this is a nice feature since
JComponentPack 1.1.0, see the screenshot for this feature:

If you want to implements the Windows explorer like feature in Java swing application, the JListView component meets your requirements exactly.
The JListView component
support the 5 different view modes: small icon, large icon, list,
thumbnails, details, all these view mode can change on the fly, the
methods “JListView.setViewMode” can change the view mode of JListView component.
The JListView component have the MVC design concept, a simple TableModel can be provided for it’s data, a simple CellProvider such IconProvider can be provided for it’s icon. Should write a DefaultCellRenderer subclass for its renderer and DefaultCellEditor subclass for it’s editor. The article “Introduce Cell Renderer” introduce why using the DefaultCellRenderer.
The JListView component use a ListSelectionModel as
it’s selection model, you can change the selection model’s mode, it
support single selection, single interval selection, multiple interval
selection, you can use the following methods to get the selected values:
The com.zfqjava.swing.model and com.zfqjava.swing.cell package have the FileTableModel and FileProvider, it support the directory list and file icon directly, the following code can create a explorer like GUI:
JListView listView = new JListView();
listView.setListData(new FileTableModel(new File(System.getProperty("user.home"))));
listView.setCellRenderer(new FileCellRenderer());
listView.setCellEditor(new FileCellEditor());
The JListView component also support row sorting, the TableModel you provided for JListView only need implements the ColumnSorter interface, it can support the row sorting automatically, we want to improve this area after upgrade the JRE version to 1.6.
The JListView component provides several important client property:
For details, you can view the
JListView JavaDoc API documentation.
The JListView also support the Drag and Drop, but in JComponentPack 1.1.0 and early version, implements this feature has trick and tips:
// get JTable and JList
BasicListViewUI ui = (BasicListViewUI)listView.getUI();
JTable table = ui.getTable();
JList list = ui.getList();
table.setDragEnabled(true);
list.setDragEnabled(true);
TransferHandler th = new TransferHandler() {
public int getSourceActions(JComponent c) {
return COPY;
}
protected Transferable createTransferable(JComponent c) {
// just a test
Object o = listView.getSelectedValue();
if(o != null) {
return new StringSelection(o.toString());
}
return null;
}
};
table.setTransferHandler(th);
list.setTransferHandler(th);
In the upcoming version JComponentPack 1.2.0, we have improved this area, so in the new version, implements the drag and drop feature is very simple:
listView.setDragEnabled(true);
TransferHandler th = new TransferHandler() {
public int getSourceActions(JComponent c) {
return COPY;
}
protected Transferable createTransferable(JComponent c) {
// just a test
Object o = listView.getSelectedValue();
if(o != null) {
return new StringSelection(o.toString());
}
return null;
}
};
listView. setTransferHandler(th);
If you want to implements the Windows explorer like feature in Java swing application, the JListView component meets your requirements exactly.
The JListView component
support the 5 different view modes: small icon, large icon, list,
thumbnails, details, all these view mode can change on the fly, the
methods “JListView.setViewMode” can change the view mode of JListView component.
The JListView component have the MVC design concept, a simple TableModel can be provided for it’s data, a simple CellProvider such IconProvider can be provided for it’s icon. Should write a DefaultCellRenderer subclass for its renderer and DefaultCellEditor subclass for it’s editor. The article “Introduce Cell Renderer” introduce why using the DefaultCellRenderer.
The JListView component use a ListSelectionModel as
it’s selection model, you can change the selection model’s mode, it
support single selection, single interval selection, multiple interval
selection, you can use the following methods to get the selected values:
The com.zfqjava.swing.model and com.zfqjava.swing.cell package have the FileTableModel and FileProvider, it support the directory list and file icon directly, the following code can create a explorer like GUI:
JListView listView = new JListView();
listView.setListData(new FileTableModel(new File(System.getProperty("user.home"))));
listView.setCellRenderer(new FileCellRenderer());
listView.setCellEditor(new FileCellEditor());
The JListView component also support row sorting, the TableModel you provided for JListView only need implements the ColumnSorter interface, it can support the row sorting automatically, we want to improve this area after upgrade the JRE version to 1.6.
The JListView component provides several important client property:
For details, you can view the
JListView JavaDoc API documentation.
The JListView also support the Drag and Drop, but in JComponentPack 1.1.0 and early version, implements this feature has trick and tips:
// get JTable and JList
BasicListViewUI ui = (BasicListViewUI)listView.getUI();
JTable table = ui.getTable();
JList list = ui.getList();
table.setDragEnabled(true);
list.setDragEnabled(true);
TransferHandler th = new TransferHandler() {
public int getSourceActions(JComponent c) {
return COPY;
}
protected Transferable createTransferable(JComponent c) {
// just a test
Object o = listView.getSelectedValue();
if(o != null) {
return new StringSelection(o.toString());
}
return null;
}
};
table.setTransferHandler(th);
list.setTransferHandler(th);
In the upcoming version JComponentPack 1.2.0, we have improved this area, so in the new version, implements the drag and drop feature is very simple:
listView.setDragEnabled(true);
TransferHandler th = new TransferHandler() {
public int getSourceActions(JComponent c) {
return COPY;
}
protected Transferable createTransferable(JComponent c) {
// just a test
Object o = listView.getSelectedValue();
if(o != null) {
return new StringSelection(o.toString());
}
return null;
}
};
listView. setTransferHandler(th);
Introduce the cell renderer and editor in JComponentPack 1.1.0
1. ObjectCellRenderer and it’s subclass such as DateCellRenderer, NumberCellRenderer is used by JDataGrid or JTable component, if you want to write a cell renderer for JDataGrid, you should extend ObjectCellRenderer.The ObjectCellEditor and it’s subclass is used by JDataGrid or JTable component.
You can view these cell renderers in the com.zfqjava.swing.cell package before reinvent the wheel.
The ObjectCellRenderer have the following subclass in com.zfqjava.swing.cell package:
BigDecimalCellRenderer,
BigIntegerCellRenderer,
BooleanCellRenderer,
DateCellRenderer,
NumberCellRenderer,
StreamCellRenderer,
URLCellRenderer
The
ObjectCellRenderer and
ObjectCellEditor and it’s subclass are managed by CellManager object,
The
JDataGrid use
the CellManger object to mange all it’s cell renderer and editor, so
you can add the renderer and editor for CellManager, you can also
remove or replace the cell renderer or editor in CellManger.
Write a ObjectCellRenderer subclass is very simple, generally you only need override it’s “setValue(java.lang.Object value)”method.
Writer a ObjectCellEditor subclass, you can override it’s three methods:
If the editing have illegal value, you should override the “commitEdit()” method and throws a ParseException.
You can use the method setValue(Object value) to save the edited value, and
Override the method getValue() to return the new value.
You can use the protected field “label” to set the text, alignment, font, etc.
2. DefaultCellRenderer and it’s subclass such as FileCellRenderer is used by JListView component, DefaultCellEditor and it’s subclass such as FileCellEditor is used by JListView component, it works with the JListView component to provide the different view modes: small icon, large icon, list, thumbnails, details, so if you want to use JListView component, you can extend the DefaultCellRenderer.
Write the DefaultCellRenderer and DefaultCellEditor is same as the ObjectCellRenderer and ObjectCellEditor, the different is you should use the protected field “iconLabel” and “textLabel” to set the icon and text.
How to use DefaultFileFilter in JComponentPack
DefaultFileFilter provide a default file filter.
It also provides some useful methods, for example:
getExtensionNames()
Return all extension of this file filter as an array.
getExtensionName ()
Return the extension of the parameter.
It could accept 3 kinds of parameter, a File, a String, an URL.
getNameWithoutExtension(
String name)
Returns the file name without extension, for example the file "readme.txt" will return "readme", include the absolute path.
getPreferredExtensionName()
Returns the preferred extension of this file filter, actually is the
first extension of your extensions. It equal this operation
getExtensionNames()[0].
It inherits from FileFilter, have two Constructors to create a instance of the FileFilter.
DefaultFileFilter(String ext, String description)
The first parameter is extension, the second parameter is description of extension.
DefaultFileFilter(String[] ext, String description)
The first parameter are extensions, the second parameter is description of extensions.
Use JBasicChart in JComponentPack
JBasicChart provides a basic chart component.
It could draw 3 styles graph, for example: PIE, LINE, BAR.
The following code demonstrates how to use JBasicChart.
JBasicChart basicChart = new JBasicChart();
basicChart.setModel(createBasicChartModel());
basicChart.setChartType(ChartType.BAR);
private BasicChartModel createBasicChartModel_() {
double[] yaxis = {1.000, 3.000, 2, 4, 0, 3.000, 0.000, 0.000, -5.000, 4.000, 3.000};
int[] xaxis = {200701, 200612, 200611, 200610, 200609, 200608, 200607, 200606,200605, 200604, 200603};
DefaultBasicChartModel model = new DefaultBasicChartModel();
model.addSeries("a", yaxis);
for (int i = 0; i < xaxis.length; i++) {
model.setCategoryName("" + xaxis[i], i);
}
return model;
}
It is easy to use JBasicChart, you could use method setModel(model)
to change the data which displayed on the chart, and also you could use
method setChartType(type) to change the style of the chart, the
parameter type is one of the three
values(ChartType.BAR、ChartType.LINE、ChartType.PIE).
To change the data of the chart, you should learn more about DefaultBasicChartModel.
addSeries(String name,
double[] values),this method add a series values which will be y-axis
value, each value have a category name, use the method setCategoryName(String name, int categoryIndex) to set it.
addSeries(String name, double[] values, int index),when you saw this method, you should know this model could add multi-series values to it.
It also have some other methods which are easy to use, for example:
getCategoryCount()
getCategoryName(int categoryIndex)
getSeriesCount()
getSeriesName(int seriesIndex)
removeSeries(int index)
etc.
For more information, please see DefaultBasicChartModel and JBasicChart.
Use JWizardPane in JComponentPack
JWizardPane is a Java wizard component in JComponentPack.
JWizardPane usage:
Sample code
JWizardPane wizardPane = new JWizardPane();
//wizardPane.setLogoIcon(logoIcon);
//wizardPane.setLogoText(logoText);
//wizardPane.getControlButton(JWizardPane.FINISH_CONTROL).setVisible(false);
//wizardPane.getControlButton(JWizardPane.HELP_CONTROL).setVisible(false);
JPanel firstPage = new JPanel(); // firstPage: the page you want to show first.
JPanel secondPage = new JPanel();
JPanel thirdPage = new JPanel();
JPanel endPage = new JPanel();
wizardPane.addPage(firstPage);
wizardPane.addPage(secondPage);
wizardPane.addPage(thirdPage);
wizardPane.addPage(endPage);
wizardPane.showFrame(“title”);
If you want to do some operations on one page, you could implement
WizardPage interface, its methods will be called automatic when click
the Next and Finish button.
The WizardPage interface have two methods:
beforeAction(JWizardPane wizardPane, WizardAction arg0)
afterAction(JWizardPane wizardPane, WizardAction arg0)
Here is an example to implement beforeAction method.
@Override
public void beforeAction(JWizardPane wizardPane, WizardAction arg0) throws ActionVetoException
{
if (arg0 == WizardAction.NEXT || arg0 == WizardAction.FINISH) {
//write the code you want to do.
}
}
Also you could implement other operations use WizardListener, for more
information, please see WizardListener in the JComponentPack.
You could obtain the Button in the wizard panel use the method
getControlButton(int buttonType), parameter must be the following value.
JWizardPane.BACK_CONTROL, for back button
JWizardPane.NEXT_CONTROL, for next button
JWizardPane.FINISH_CONTROL, for finish button
JWizardPane.HELP_CONTROL, for help button
JWizardPane.CANCEL_CONTROL, for cancel button.
It have two way to show.one is showDialog,the other is showFrame.
showDialog(Component parent)
Pops up a dialog contains the JWizardPane and parented to parent with the dialog having a default title.
showDialog(Component parent, String title)
Pops up a dialog contains the JWizardPane and parented to parent with the dialog use the special title.
showFrame()
Pops up a frame contains the JWizardPane with the frame having a default title
showFrame(String title)
Pops up a frame contains the JWizardPane and with the frame use the special title.
If you want to pause the wizard page at current page, just throw a ActionVetoException is ok.
throw new ActionVetoException();
It also provide other functions, For more information, please see JWizardPane .
JComponentPack Plug-in for NetBeans IDE 6.5
Installation
1. Download the JComponentPack Product and JComponentPack Plug-in for NetBeans IDE from:
JComponentPack Product Evaluation Version: componentpack-1_5_0-eval.zip (Size: 5.10 MB)
JComponentPack Plug-in for NetBeans IDE: com-zfqjava-ide-netbeans.nbm (Size: 1.84 MB)
2. Click “Tools -> Plugins” to open the Plug-in Manager, then at “Downloaded” Tab add the plugin:
3. Select the Plug-in “JComponentPack” and then click “Install”.
Introduction
After Installation, restart the NetBeans IDE, you will find the following changes:
1. At the Toolbar, you will find the Plug-in button:
2. At the Library Manager, the Library named “JComponentPack” has been added:

3. At the Component Palette window, the “JComponentPack” category has been added:
You can drag the component at the Palette to your form:
Main Window
Click the new added button on the Toolbar, the following window will open:
You can configure the latest JComponentPack version, just choose the JComponentPack product directory.
Usage
License Tool
Request Evaluation License:
You can request a evaluation license, a free evaluation licensewillsend
to your email box shortly, please input your real emailaddress toavoid
cannot receive the license,
we value your privacy.
Input License:
After you receive the license, you can input the license data here.
Generate Java Code:
Ifyou want to use our product on your project, you need
configurethelicense correctly, this tool will help you generate a Java
String.
Then invoke the following code: // the code means the above license data
LicenseManager.getInstance().addLicenseData(code);
Run JComponentPack Demo:
You can run the several JComponentPack Demo at NetBeans IDEdirectly,you
need configure the JComponentPack product home at first.Run
JDataGridBean: This will launch the JDataGridBean application.
Run DataGridDemo: This will launch the many JDataGrid Spreadsheet Edition demos.
Run JDataTableBean: This will launch the JDataTableBean application.
Run ComponentSetDemo: This will launch the individual component demo,such as JListView, JFontChooser, JCalendar, JWizardPane.
NetBeans IDE Integration:
Add as Class Library: This will adds the current JComponentPack product to the Class Library.
Resources:
There are several documents to help you learning and using the JComponentPack product.
Tips
If you configure the JComponentPack product home directory to
thelicensed binary version, you will view the JavaDoc API in your
codeeditor of NetBeans IDE directly, configure it to the licensed
sourcecode version, you will view the source code and JavaDoc API in
yourcode editor directly. After you configure the JComponentPack
producthome directory, you should run "Add as Class Library" again to
makeyour configuration works.
How to get the JComponentPack product binary version or source version?
Get it Now!
Configure it and the JComponentPack Plug-in for NetBeans IDE
willaccelerate your project development process, save time,
reducecosts for your team.
Use?JPrintPreview?and?PrintFactory?in?JComponentPack
JPrintPreview?is a Java Print Preview component in?JComponentPack.
PrintFactory?is a utility class in?com.zfqjava.swing?package to generate printable in?JComponentPack.
PrintFactory?usage.
createPrintable(Component?comp,?Map?map)
createPrintable(Image?image,?Map?map)
It need two parameters, the first is a instance of Image or a instance
of Component, the second parameter is a instance of Map, t
How to import Excel file into JTable
Here are three way to do this.Use "JTableReadTableModelTask " to do this. ( recommended )Use "ReadTableModelTask" to do thisUse ModelIO to do this.
The first and second the way will run in the background thread, the third way will run in current thread.
1. Use "JTableReadTableModelTask "to do this. (recommended)
Here is the sample code to import excel file: JTable jTable = new JTable();
String excelFileName = "excelFileNa
Introduce the AComboBox component
Overview
The AComboBox is a drop down component in JComponentPack product, it’s different with the “JComboBox” component in the core JavaSwing package, it can set the popup icon, popup component, etc.
Main Features
1. Customize the popup icon
The AComboBox component have the method “setPopupIcon(Icon)”, you can change the popup icon for your requirements, see the screenshot:
2. Customize the popup
How to use JLinkButton
JLinkButton
inherit from JButton,it have all function of JButton, and it also have
a additional function, you can open a Explorer via URL and that don’t
need write code.
There are two ways to use this function:
1.JLinkButton linkButton = new JLinkButton(“www. baidu.com”);
URL url = new URL(“www.baidu.com”);
linkButton.setURL(url);
2. URL url = new URL(“www.baidu.com”);
JLinkButton linkButton = n
How to use "JComponentPack" in the NetBeans IDE 6.11. right click on Palette window,and select 'Palette manager...' .2. click 'New Category' button,enter a name then click 'Ok' button.3. click 'Add from Library...' button, and select a lib from 'Available Libraries',then click next button.4. select the component you need to use,and click next.5. select the 'Palette Categories' you want put the component into,then click finishe
How to disable the splash screen in JDataGridBean?
1. Understand the JBean's splash API.
JBean provide the following API related the splash screen:
JBean.doSplash();
This methods will show the splash screen when it’s not open, and hide the screen window when it’s visible.
JBean. isShowSplashOnStartup();
JBean. setShowSplashOnStartup(Boolean);
These two API provides a property to control whether show the splash
screen windo