JComponentPack 是一個基于Java Swing的GUI類庫,一系列可視化的JavaBeans集合,它基于Swing的MVC架構,是100%的純Java類庫,它包括20多個Swing 所沒有的控件,如EXCEL風格Java的電子表格控件,讀取數據庫表的Java表格控件,日歷控件,類似資源管理器的列表控件,向導框架等等,這些 JavaBeans可以直接拖動到您的圖形用戶界面,它可提高您的工作效率,加快您的項目開發過程。
JBean應用程序框架提供了一個標準的Swing應用程序框架,它支持從屬性文件創建Actions,創建和動態顯示菜單,也支持創建單選按鈕,多選按鈕,能動態改變按鈕狀態。它提供了一個資源管理類,能夠從定義好的資源文件裝載小圖標,菜單和按鈕的資源。
JBean應用程序框架包含了一些常用的標準控件,包括打印和打印預覽控件,狀態欄控件,登陸對話框,反饋對話框,外觀改變對話框等。
JBean應用程序框架包含了一些常用的單元格繪制和編輯器,它們支持通用的數據類型,包括數字,日期,文件,圖表,顏色等類型。這些單元格繪制和編輯器也提供了不同的控件支持,包括復選框,下拉框等。
JComponentSet是一個Java swing控件集,包括JWizardPane, JListView, Layout Suite (CellLayout, BoxLayout2, CardLayout2, GridLayout2), JDirChooser, JCalendar, JFontChooser, JLinkButton, JSidePane, JSideBar, JImageViewer, XTree, XCheckBox, JCardPane, JGridPane等一系列控件.
· 圖形控件
提供了常見的圖形, 2D圖形和3D圖形.
· 圖表控件
支持3種不同的圖表類型, 分別是餅形圖,條形圖和線形圖.
· 核心公式框架
核心公式框架定義了一個通用的公式框架,包括函數和公式定義,公式解析器等接口。
支持輸入和輸出多種文件格式,包括csv, html, txt.
JDataGrid電子表格控件是了一個Java swing 電子表格控件,提供了基本的功能,如撤銷和重做,合并單元格,拼寫檢查,Excel文件的輸入和輸出,打印和打印預覽等,也包括了復雜的高級功能.
· 電子表格公式
支持許多函數,例如邏輯函數, 日期函數, 數學計算函數, 文本函數, 單元格函數, 和部分的統計函數.
支持輸入和輸出多種文件格式,包括Excel xls, Excel xml, PDF等.
最新的JDataGrid電子表格控件支持JavaFX平臺,新添加了JavaFX控件"DataGrid"和"DataGridBean",您可以在JavaFX腳本中直接使用這些控件,這些JavaFX控件直接支持最新的JDataGrid電子表格服務器端控件。
最新的JDataGrid電子表格服務器端控件能部署在JavaEE應用服務器上,JDataGrid小程序直接支持最新的服務器端控件,您可以通過簡單的設置,設置一個服務器端控件的URL,就能讀取,保存,下載各種不同格式的電子表格文件,所有的配置在服務器端完成。
JDataGrid數據庫控件是一個能夠直接對數據庫操作的表格,基于標準的JDBC技術,能夠直接操作ResultSet和RowSet,并提供如打印和打印預覽,多種格式的文件輸入和輸出的功能.
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: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 JListView component provides several methods for it’s editing:
JListView.isEditing(); // determines whether the JListView is being edited.
JListView.cancelEditing(); // cancel current editing
JListView.stopEditing(); // stop the current editing and apply the editing value
JListView.startEditingAtIndex(); // start the editing at the specified index
JListview.getEditingInex(); // get the current editing object’s index
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:
“JListView.rowSelectionAllowed” allow the full row can be selected
“JListView.showVerticalLines” shows the vertical lines in details view mode.
“JListView.showHorizontalLines” shows the horizontal lines in details view mode.
“JListView.backgroundImage” sets the background image for JListView component.
The JListView also support the Drag and Drop, but in JComponentPack 1.1.0 and early version, implements this feature has trick and tips:
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 JListView component provides several methods for it’s editing:
JListView.isEditing(); // determines whether the JListView is being edited.
JListView.cancelEditing(); // cancel current editing
JListView.stopEditing(); // stop the current editing and apply the editing value
JListView.startEditingAtIndex(); // start the editing at the specified index
JListview.getEditingInex(); // get the current editing object’s index
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:
“JListView.rowSelectionAllowed” allow the full row can be selected
“JListView.showVerticalLines” shows the vertical lines in details view mode.
“JListView.showHorizontalLines” shows the horizontal lines in details view mode.
“JListView.backgroundImage” sets the background image for JListView component.
The JListView also support the Drag and Drop, but in JComponentPack 1.1.0 and early version, implements this feature has trick and tips:
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);
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:
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:
protected void |
|
protected Object |
getValue() |
protected void |
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.
DefaultFileFilter provide a default file filter.
It also provides some useful methods, for example:
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.
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.
For more information, please see DefaultBasicChartModel and JBasicChart.
JWizardPane is a Java wizard component in JComponentPack.
JWizardPane usage:
Sample codeIf 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:
You could obtain the Button in the wizard panel use the method
getControlButton(int buttonType), parameter must be the following value.
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 .