當前位置: 首頁>>代碼示例>>Java>>正文


Java TableRowSorter.setSortable方法代碼示例

本文整理匯總了Java中javax.swing.table.TableRowSorter.setSortable方法的典型用法代碼示例。如果您正苦於以下問題:Java TableRowSorter.setSortable方法的具體用法?Java TableRowSorter.setSortable怎麽用?Java TableRowSorter.setSortable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.table.TableRowSorter的用法示例。


在下文中一共展示了TableRowSorter.setSortable方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import javax.swing.table.TableRowSorter; //導入方法依賴的package包/類
@Override
public void run() {
	List<Song> songs = this.getResult();
	Exception ex = this.getException();
	SongSearch search = this.getSearch();
	if (ex == null) {
		SongSearchTableModel model = null;
		if (songs != null && songs.size() > 0) {
			model = new SongSearchTableModel(search, songs);
		} else {
			model = new SongSearchTableModel();
		}
		tblSongSearchResults.setModel(model);
		// reset the scrollbar position
		scrSongSearchResults.getVerticalScrollBar().setValue(0);
		setSongSearchTableWidths();
		tblSongSearchResults.getColumnModel().getColumn(0).setCellRenderer(new SongSearchCheckTableCellRenderer(tblSongSearchResults.getDefaultRenderer(Boolean.class)));
		tblSongSearchResults.getColumnModel().getColumn(1).setCellRenderer(new SongSearchTitleTableCellRenderer());
		tblSongSearchResults.getColumnModel().getColumn(2).setCellRenderer(new SongSearchMatchTableCellRenderer(search));
		// disable sorting any column other than the title column
		// it doesn't make sense to sort the matched text or selection column
		TableRowSorter<SongSearchTableModel> sorter = new TableRowSorter<SongSearchTableModel>(model);
		sorter.setSortable(0, false);
		sorter.setSortable(2, false);
		tblSongSearchResults.setRowSorter(sorter);
	} else {
		String message = MessageFormat.format(Messages.getString("panel.song.data.search.exception.text"), search.getText());
		ExceptionDialog.show(
				SongsPanel.this, 
				Messages.getString("panel.song.data.search.exception.title"), 
				message, 
				ex);
		LOGGER.error(message, ex);
	}
}
 
開發者ID:wnbittle,項目名稱:praisenter,代碼行數:36,代碼來源:SongsPanel.java

示例2: createControls

import javax.swing.table.TableRowSorter; //導入方法依賴的package包/類
private void createControls(final List<BaseType> baseTypes) {
  setBorder(new EmptyBorder(5, 5, 5, 5));
  final GridBagLayout gridBagLayout = new GridBagLayout();
  gridBagLayout.columnWidths = new int[] {0, 0, 0};
  gridBagLayout.rowHeights = new int[] {0, 0, 0, 0, 0};
  gridBagLayout.columnWeights = new double[] {0.0, 1.0, Double.MIN_VALUE};
  gridBagLayout.rowWeights = new double[] {0.0, 0.0, 1.0, 1.0, Double.MIN_VALUE};
  setLayout(gridBagLayout);

  final JLabel lblName = new JLabel("Name:");
  GridBagConstraints gbcLblName = new GridBagConstraints();
  gbcLblName.insets = new Insets(0, 0, 5, 5);
  gbcLblName.anchor = GridBagConstraints.WEST;
  gbcLblName.gridx = 0;
  gbcLblName.gridy = 0;
  add(lblName, gbcLblName);

  name = new JTextField();
  GridBagConstraints gbcName = new GridBagConstraints();
  gbcName.insets = new Insets(0, 0, 5, 0);
  gbcName.fill = GridBagConstraints.HORIZONTAL;
  gbcName.gridx = 1;
  gbcName.gridy = 0;
  add(name, gbcName);
  name.setColumns(10);

  final JLabel lblMembers = new JLabel("Members:");
  final GridBagConstraints gbcLblMembers = new GridBagConstraints();
  gbcLblMembers.anchor = GridBagConstraints.WEST;
  gbcLblMembers.insets = new Insets(0, 0, 5, 5);
  gbcLblMembers.gridx = 0;
  gbcLblMembers.gridy = 2;
  add(lblMembers, gbcLblMembers);

  final MemberTableModel model = new MemberTableModel();
  model.addTableModelListener(new MemberTableModelListener());
  members = new MemberTable(model, baseTypes);
  final TableRowSorter<MemberTableModel> sorter = new TableRowSorter<MemberTableModel>(model);
  // Triggers immediate re-sort when offset is updated.
  sorter.setSortsOnUpdates(true);
  sorter.setSortable(MemberTableModel.NAME_COLUMN, false);
  sorter.setSortable(MemberTableModel.TYPE_COLUMN, false);
  // Initial state is ascending sort order.
  sorter.toggleSortOrder(MemberTableModel.INDEX_COLUMN);
  members.setRowSorter(sorter);

  final GridBagConstraints gbcMembers = new GridBagConstraints();
  gbcMembers.insets = new Insets(0, 0, 5, 0);
  gbcMembers.fill = GridBagConstraints.BOTH;
  gbcMembers.gridx = 1;
  gbcMembers.gridy = 2;
  add(new JScrollPane(members), gbcMembers);

  final JLabel lblPreview = new JLabel("Preview:");
  final GridBagConstraints gbcLblPreview = new GridBagConstraints();
  gbcLblPreview.anchor = GridBagConstraints.WEST;
  gbcLblPreview.insets = new Insets(0, 0, 0, 5);
  gbcLblPreview.gridx = 0;
  gbcLblPreview.gridy = 3;
  add(lblPreview, gbcLblPreview);

  final JTextArea preview = new JTextArea();
  final GridBagConstraints gbcPreview = new GridBagConstraints();
  gbcPreview.fill = GridBagConstraints.BOTH;
  gbcPreview.gridx = 1;
  gbcPreview.gridy = 3;
  add(preview, gbcPreview);
}
 
開發者ID:google,項目名稱:binnavi,代碼行數:69,代碼來源:ComplexTypePanel.java

示例3: sort

import javax.swing.table.TableRowSorter; //導入方法依賴的package包/類
/**
       * Toggle-sort a column
       * @param columnIndex The index of the column to be sorted
       */
@SuppressWarnings({ "unchecked", "rawtypes" })
private void sort(int columnIndex){
	// Get the default, already registered, sorter
	TableRowSorter sorter = (TableRowSorter)getTable().getRowSorter();
	// Ensure the row is sortable
	sorter.setSortable(columnIndex, true); 
	// Disable the row sorting capability to remove the native functionality
	sorter.toggleSortOrder(columnIndex);
	// Let all listeners (ui-display-related objects) know that we've sorted, so
	// please repaint()
	int rowCount = getTable().getRowCount();
	getModel().fireTableRowsUpdated(0, rowCount - 1);
	// If the column clicked doesn't match the last column that was sorted, there is
	// no need to toggle, and we'll just sort descending
	if (lastSorted != columnIndex){
		descending = true;
		lastSorted = columnIndex;
	}
	// If the direction is descending, sort descending
	if (descending){
		sorter.setSortKeys( Arrays.asList( new RowSorter.SortKey( columnIndex, SortOrder.DESCENDING ) ) );
	}
	// Otherwise, sort ascending
	else {
		sorter.setSortKeys( Arrays.asList( new RowSorter.SortKey( columnIndex, SortOrder.ASCENDING ) ) );
	}
	// Toggle the sort direction, in case we click on the chosen column again
	descending = !descending;
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:34,代碼來源:GridPlaySheet.java


注:本文中的javax.swing.table.TableRowSorter.setSortable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。