JComponentPack Programmer Guide > JListView
Code Samples:
|
The JListView support 5 different view mode: small icon, large icon, list, details, thumbnail.
Code Samples:
|
TableModel used by
JListView should implement ColumnSorter interface.
Support Action
When double click or the "ENTER" key on the keyboard has been pressed,
the JListView component will generate an action event.
Code Samples:
// add the action listener
listView.addActionListener(new MyActionListener());
Background Image
The JListView comonent supports background image.
Code Samples:
// set the background image
Image img = new ImageIcon(file.toURL()).getImage();
listView.putClientProperty("JListView.backgroundImage", img);
Drag and Drop
The JListView component support the feature drag and drop directly.
Code Samples:
// enable the default drag and drop
listView.setDragEnabled(true);
// customize the drag and drop behavior by self
listView.setTransferHandler(new MyTransferHandler());
Size Column to Fit
The JListView component support the feature size the column width to fit it's contents, the JListView component will size the element column to fit it's contents by default.
Code Samples:
// set the second column to fit it's contents
listView.sizeColumnWidthToFit(1);
Customize Cell Renderer and Editor
You can customize the JListView's cell renderer and editor for your requirements.
Code Samples:
// set my cell renderer
listView.setCellRenderer(new MyCellRenderer());
// set my cell editor
listView.setCellEditor(new MyCellEditor());
File Explorer
The JListView component provides a default file component factory, it includes a FileTableMode to support view directory like Explorer, a default cell renderer and cell editor to display the file's large icon, small icon, thumbnails, a default file TransferHandler to support drag and drop the file object.
Code Samples:
// view the file directory like explorer
listView.setListData(new FileTableModel(f, false, listView));
View Zip or Jar file (New Features since JComponentPack 1.5)
The JListView component provides a default zip file component factory, it includes a ZipFileTableMode to support view the zip file contents.
Code Samples:
// view a zip file
ZipFile zipFile = new ZipFile(f);
ZipFileTableModel model = new ZipFileTableModel(zipFile, listView);
listView.setListData(model);
Row Selection Mode
The JListView component support row selection mode in details mode, the following code will enable the row selection mode:
Code Samples:
// enable the row selection mode
listView.putClientProperty("JListView.rowSelectionAllowed", Boolean.TRUE);
Show Horizontal Lines and Vertical Lines
In JListView component, you can show the horizontal lines and vertical lines in details mode.
Code Samples:
// Show Horizontal Lines
listView.putClientProperty("JListView.showHorizontalLines", Boolean.TRUE);
// Show Vertical Lines
listView.putClientProperty("JListView.showVerticalLines", Boolean.TRUE);
Related JavaDoc API List
JListView
FileTableModel
ZipFileTableModel
DefaultCellEditor
DefaultCellRenderer
FileCellEditor
FileCellRenderer
ZipEntryCellEditor
ZipEntryCellRenderer
Copyright (C) 2009 Extreme Component, Inc. All rights reserved.