当前位置: 首页>>代码示例>>Java>>正文


Java JTable.getSelectedRows方法代码示例

本文整理汇总了Java中javax.swing.JTable.getSelectedRows方法的典型用法代码示例。如果您正苦于以下问题:Java JTable.getSelectedRows方法的具体用法?Java JTable.getSelectedRows怎么用?Java JTable.getSelectedRows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTable的用法示例。


在下文中一共展示了JTable.getSelectedRows方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTransferable

import javax.swing.JTable; //导入方法依赖的package包/类
/******* Export Side *******/

	/* Create data from the selected rows and columns */
	@Override
	protected Transferable createTransferable(JComponent c)
	{
		JTable table = (JTable)c;
		rowsidx = table.getSelectedRows();
		colsidx = table.getSelectedColumns();

		Run store[][] = new Run[rowsidx.length][colsidx.length];
		for (int ii = 0; ii < rowsidx.length; ii++)
			for (int jj = 0; jj < colsidx.length; jj++)
				store[ii][jj] = (Run)table.getValueAt(rowsidx[ii], colsidx[jj]);

		return new SimpleDataTransfer(flavor, store);
	}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:18,代码来源:RunsTable.java

示例2: onClick

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public void onClick(ActionEvent i_Event)
{
    if ( JavaHelp.isNull(this.getAppFrame().getTableName()) )
    {
        this.getAppFrame().showHintInfo("请先选择要清空的表" ,Color.BLUE);
        return;
    }
    
    if ( this.getAppFrame().getSelectColCount() <= 1 )
    {
        this.getAppFrame().showHintInfo("请选择查询结果列表中的多行数据" ,Color.BLUE);
        return;
    }
    
    
    JTable v_JTable      = (JTable)XJava.getObject("xtDataList");
    int [] v_RowIndexArr = v_JTable.getSelectedRows();
    
    String v_CMDPuts = this.writeContents(v_JTable ,v_RowIndexArr);
    
    ((JTextArea)XJava.getObject("xtPutsInfo")).setText(v_CMDPuts);
    
    super.onClick(i_Event);
}
 
开发者ID:HY-ZhengWei,项目名称:HBaseClient,代码行数:26,代码来源:CopyActionListener.java

示例3: pasteFromClipboard

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * Reads clipboard data and converts it into supported format and fills the
 * tmodel cells
 *
 * @param table the target tmodel
 */
private static void pasteFromClipboard(JTable table) {
    int startRow = table.getSelectedRows()[0];
    int startCol = table.getSelectedColumns()[0];
    String pasteString;
    try {
        pasteString = (String) (CLIPBOARD.getContents(CLIPBOARD).getTransferData(DataFlavor.stringFlavor));
    } catch (UnsupportedFlavorException | IOException ex) {
        Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, ex);
        return;
    }
    String[] lines = pasteString.split(LINE_BREAK);
    for (int i = 0; i < lines.length; i++) {
        String[] cells = lines[i].split(CELL_BREAK);
        if (table.getRowCount() <= startRow + i) {
            ((DefaultTableModel) table.getModel()).addRow(nullRow);
        }
        for (int j = 0; j < cells.length; j++) {
            if (table.getColumnCount() > startCol + j) {
                if (table.isCellEditable(startRow + i, startCol + j)) {
                    table.setValueAt(cells[j], startRow + i, startCol + j);
                }
            }
        }
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:32,代码来源:JtableUtils.java

示例4: copyToClipboard

import javax.swing.JTable; //导入方法依赖的package包/类
public static void copyToClipboard(JTable table, boolean isCut) {
    int numCols = table.getSelectedColumnCount();
    int numRows = table.getSelectedRowCount();
    int[] rowsSelected = table.getSelectedRows();
    int[] colsSelected = table.getSelectedColumns();
    if (numRows != rowsSelected[rowsSelected.length - 1] - rowsSelected[0] + 1 || numRows != rowsSelected.length
            || numCols != colsSelected[colsSelected.length - 1] - colsSelected[0] + 1 || numCols != colsSelected.length) {

        Logger.getLogger(XTableUtils.class.getName()).info("Invalid Copy Selection");
        return;
    }
    if (table.getModel() instanceof UndoRedoModel) {
        ((UndoRedoModel) table.getModel()).startGroupEdit();
    }

    StringBuilder excelStr = new StringBuilder();

    for (int i = 0; i < numRows; i++) {
        for (int j = 0; j < numCols; j++) {
            excelStr.append(escape(table.getValueAt(rowsSelected[i], colsSelected[j])));
            if (isCut) {
                table.setValueAt("", rowsSelected[i], colsSelected[j]);
            }
            if (j < numCols - 1) {
                excelStr.append(CELL_BREAK);
            }
        }
        excelStr.append(LINE_BREAK);
    }

    if (table.getModel() instanceof UndoRedoModel) {
        ((UndoRedoModel) table.getModel()).stopGroupEdit();
    }

    StringSelection sel = new StringSelection(excelStr.toString());

    CLIPBOARD.setContents(sel, sel);
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:39,代码来源:XTableUtils.java

示例5: valueChanged

import javax.swing.JTable; //导入方法依赖的package包/类
public void valueChanged(ListSelectionEvent e) 
{
    JTable v_JTable = (JTable)XJava.getObject("xtDataList");
    
	// 如果事件非快速连续事件之一
	if ( !e.getValueIsAdjusting() )
	{
		int [] v_RowIndexArr = v_JTable.getSelectedRows();
		
		if ( v_RowIndexArr.length == 1 )
		{
		    ((JTextComponent)XJava.getObject("Edit_RowKey"))     .setText(        v_JTable.getValueAt(v_RowIndexArr[0] ,1).toString());
		    ((JComboBox)     XJava.getObject("Edit_ColumnName")) .setSelectedItem(v_JTable.getValueAt(v_RowIndexArr[0] ,3).toString());
		    ((JTextComponent)XJava.getObject("Edit_ColumnValue")).setText(        v_JTable.getValueAt(v_RowIndexArr[0] ,4).toString());
		    ((JButton)       XJava.getObject("xbCopy"))          .setEnabled(false);
		    
	        // 设置列族名下拉列表框
	        String    v_FamilyName    = v_JTable.getValueAt(v_RowIndexArr[0] ,2).toString();
	        JComboBox v_FamilyNameObj = (JComboBox)XJava.getObject("Edit_FamilyName");
	        for (int i=0; i<v_FamilyNameObj.getItemCount(); i++)
	        {
	            if ( v_FamilyNameObj.getItemAt(i).toString().equals(v_FamilyName) )
	            {
	                v_FamilyNameObj.setSelectedIndex(i);
	                return;
	            }
	        }
		}
		else
		{
		    // 多行选择的情况
		    ((JTextComponent)XJava.getObject("Edit_RowKey"))     .setText("");
		    ((JComboBox)     XJava.getObject("Edit_FamilyName")) .setSelectedIndex(0);
               ((JComboBox)     XJava.getObject("Edit_ColumnName")) .setSelectedIndex(0);
               ((JTextComponent)XJava.getObject("Edit_ColumnValue")).setText("");
               ((JButton)       XJava.getObject("xbCopy"))          .setEnabled(this.getAppFrame().getSelectColCount() >= 2);
		}
	}
}
 
开发者ID:HY-ZhengWei,项目名称:HBaseClient,代码行数:40,代码来源:ResultsSelectionListener.java

示例6: pasteFromAbove

import javax.swing.JTable; //导入方法依赖的package包/类
public static void pasteFromAbove(JTable table) {
    int startRow = table.getSelectedRows()[0];
    int[] cols = table.getSelectedColumns();
    for (int col : cols) {
        table.setValueAt(table.getValueAt(startRow - 1, col), startRow, col);
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:8,代码来源:JtableUtils.java

示例7: ClearSelection

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * clear selection by setting empty values
 *
 * @param table to be cleared
 */
private static void ClearSelection(JTable table) {
    int[] srow = table.getSelectedRows();
    int[] scol = table.getSelectedColumns();
    int lastSrow = srow.length;
    int lastScol = scol.length;
    for (int i = 0; i < lastSrow; i++) {
        for (int j = 0; j < lastScol; j++) {
            if (table.isCellEditable(srow[i], scol[j])) {
                table.setValueAt("", srow[i], scol[j]);
            }
        }
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:19,代码来源:JtableUtils.java

示例8: copyToClipboard

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * Reads the cell values of selected cells of the <code>tmodel</code> and
 * uploads into clipboard in supported format
 *
 * @param isCut CUT flag,<code>true</code> for CUT and <code>false</code>
 * for COPY
 * @param table the source for the action
 * @see #escape(java.lang.Object)
 */
private static void copyToClipboard(boolean isCut, JTable table) {
    try {
        int numCols = table.getSelectedColumnCount();
        int numRows = table.getSelectedRowCount();
        int[] rowsSelected = table.getSelectedRows();
        int[] colsSelected = table.getSelectedColumns();
        if (numRows != rowsSelected[rowsSelected.length - 1] - rowsSelected[0] + 1 || numRows != rowsSelected.length
                || numCols != colsSelected[colsSelected.length - 1] - colsSelected[0] + 1 || numCols != colsSelected.length) {
            JOptionPane.showMessageDialog(null, "Invalid Selection", "Invalid Selection", JOptionPane.ERROR_MESSAGE);
            return;
        }
        StringBuilder excelStr = new StringBuilder();
        for (int i = 0; i < numRows; i++) {
            for (int j = 0; j < numCols; j++) {
                excelStr.append(escape(table.getValueAt(rowsSelected[i], colsSelected[j])));
                if (isCut) {
                    if (table.isCellEditable(rowsSelected[i], colsSelected[j])) {
                        table.setValueAt("", rowsSelected[i], colsSelected[j]);
                    }
                }
                if (j < numCols - 1) {
                    excelStr.append(CELL_BREAK);
                }
            }
            if (i < numRows - 1) {
                excelStr.append(LINE_BREAK);
            }
        }
        if (!excelStr.toString().isEmpty()) {
            StringSelection sel = new StringSelection(excelStr.toString());
            CLIPBOARD.setContents(sel, sel);
        }

    } catch (HeadlessException ex) {
        Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:47,代码来源:JtableUtils.java

示例9: deleterow

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * get all selected rows and DELETE one by one from the last.
 *
 * @param table the table to DELETE rows
 */
public static void deleterow(JTable table) {
    int[] selectedrows = table.getSelectedRows();
    for (int row : selectedrows) {
        row = table.getSelectedRow();
        if (table.getRowSorter() != null) {
            row = table.getRowSorter().convertRowIndexToModel(row);
        }
        ((DefaultTableModel) table.getModel()).removeRow(row);
    }

}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:17,代码来源:JtableUtils.java

示例10: pasteFromClipboard

import javax.swing.JTable; //导入方法依赖的package包/类
public static void pasteFromClipboard(JTable table) {
    int startRow = table.getSelectedRows()[0];
    int startCol = table.getSelectedColumns()[0];

    String pasteString;
    try {
        pasteString = (String) (CLIPBOARD.getContents(null).getTransferData(DataFlavor.stringFlavor));
    } catch (Exception e) {
        Logger.getLogger(XTableUtils.class.getName()).log(Level.WARNING, "Invalid Paste Type", e);
        return;
    }
    if (table.getModel() instanceof UndoRedoModel) {
        ((UndoRedoModel) table.getModel()).startGroupEdit();
    }
    String[] lines = pasteString.split(LINE_BREAK);

    for (int i = 0; i < lines.length; i++) {
        String[] cells = lines[i].split(CELL_BREAK);
        for (int j = 0; j < cells.length; j++) {
            if (table.getRowCount() <= startRow + i) {
                if (table.getModel() instanceof DataModel) {
                    if (!((DataModel) table.getModel()).addRow()) {
                        return;
                    }
                }
            }
            if (table.getRowCount() > startRow + i && table.getColumnCount() > startCol + j) {
                table.setValueAt(cells[j], startRow + i, startCol + j);
            }
        }
    }
    if (table.getModel() instanceof UndoRedoModel) {
        ((UndoRedoModel) table.getModel()).stopGroupEdit();
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:36,代码来源:XTableUtils.java

示例11: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    JComponent comp = (JComponent) defCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    Boolean rowSelected = false;
    for (int srow : table.getSelectedRows()) {
        if (srow == row) {
            rowSelected = true;
            break;
        }
    }

    setSelectionColor(rowSelected, isSelected, comp, table.getBackground());
    setSearchColor(comp, row, column, isSelected);
    return comp;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:16,代码来源:XTable.java

示例12: createTransferable

import javax.swing.JTable; //导入方法依赖的package包/类
/******* Export Side *******/

	/* Create data from the selected rows */
	@Override
	protected Transferable createTransferable(JComponent c)
	{
		JTable table = (JTable)c;
		rowsidx = table.getSelectedRows();

		Entrant store[] = new Entrant[rowsidx.length];
		for (int ii = 0; ii < rowsidx.length; ii++)
			store[ii] = (Entrant)table.getValueAt(rowsidx[ii], 0);

		return new SimpleDataTransfer(flavor, store);
	}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:16,代码来源:DriverTable.java

示例13: getSelection

import javax.swing.JTable; //导入方法依赖的package包/类
private String getSelection() {
    JTable table = (JTable) component;
    boolean rowSelectionAllowed = table.getRowSelectionAllowed();
    boolean columnSelectionAllowed = table.getColumnSelectionAllowed();

    if (!rowSelectionAllowed && !columnSelectionAllowed) {
        return null;
    }

    int[] rows = table.getSelectedRows();
    int[] columns = table.getSelectedColumns();
    int rowCount = table.getRowCount();
    int columnCount = table.getColumnCount();

    if (rows.length == rowCount && columns.length == columnCount) {
        return "all";
    }

    if (rows.length == 0 && columns.length == 0) {
        return "";
    }

    StringBuffer text = new StringBuffer();

    text.append("rows:[");
    for (int i = 0; i < rows.length; i++) {
        text.append(rows[i]);
        if (i != rows.length - 1) {
            text.append(",");
        }
    }
    text.append("],");
    text.append("columns:[");
    for (int i = 0; i < columns.length; i++) {
        String columnName = getColumnName(columns[i]);
        text.append(escape(columnName));
        if (i != columns.length - 1) {
            text.append(",");
        }
    }
    text.append("]");
    return text.toString();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:44,代码来源:RTable.java

示例14: onClick

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public void onClick(ActionEvent i_Event)
{
    JTable      v_JTable      = (JTable)XJava.getObject("xtDataList");
    int []      v_RowIndexArr = v_JTable.getSelectedRows();
    List<HData> v_HDatas      = new ArrayList<HData>();
    
    if ( v_RowIndexArr.length <= 0 )
    {
        this.getAppFrame().showHintInfo("请先选择要删除行" ,Color.BLUE);
        return;
    }
    
    
    int v_Ret = JOptionPane.showConfirmDialog(this.getAppFrame() ,"确认要删除选中的记录?删除后将无法恢复。" ,"确认对话框" , JOptionPane.YES_NO_OPTION);
    
    if ( v_Ret == JOptionPane.YES_OPTION )
    {
        // Nothing.
    }
    else
    {
        this.getAppFrame().showHintInfo("您取消了删除操作" ,Color.BLUE);
        return;
    }
    
    
    for (int i=0; i<v_RowIndexArr.length; i++)
    {
        HData v_HData = new HData();
        
        v_HData.setRowKey(    v_JTable.getValueAt(v_RowIndexArr[i] ,1).toString());
        v_HData.setFamilyName(v_JTable.getValueAt(v_RowIndexArr[i] ,2).toString());
        v_HData.setColumnName(v_JTable.getValueAt(v_RowIndexArr[i] ,3).toString());
        
        v_HDatas.add(v_HData);
    }
    
    try
    {
        this.getHBase().delete(this.getTableName() ,v_HDatas);
        
        for (int i=v_RowIndexArr.length-1; i>=0; i--)
        {
            this.getAppFrame().getTableModel().removeRow(v_RowIndexArr[i]);
        }
        
        this.getAppFrame().showHintInfo("成功删除 " + v_HDatas.size() + " 条信息" ,Color.BLUE);
    }
    catch (Exception exce)
    {
        this.getAppFrame().showHintInfo("删除异常:" + exce.getMessage() ,Color.RED);
    }
}
 
开发者ID:HY-ZhengWei,项目名称:HBaseClient,代码行数:55,代码来源:DeleteActionListener.java

示例15: onClick

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public void onClick(ActionEvent arg0)
{
    if ( JavaHelp.isNull(this.getAppFrame().getTableName()) )
    {
        this.getAppFrame().showHintInfo("请先选择要导出的表" ,Color.BLUE);
        return;
    }
    
    if ( this.getAppFrame().getRowCount() == 0 )
    {
        this.getAppFrame().showHintInfo("查询结果无数据,无法导出" ,Color.BLUE);
        return;
    }
    
    
    JTable        v_JTable      = (JTable)XJava.getObject("xtDataList");
    int []        v_RowIndexArr = v_JTable.getSelectedRows();
    StringBuilder v_FileName    = new StringBuilder();
    
    // 生成文件名称
    v_FileName.append(this.getTableName());
    if ( v_RowIndexArr.length <= 0 )
    {
        String v_Text = "";
        
        v_Text = ((JTextComponent)XJava.getObject("RowKey"))     .getText();
        if ( !JavaHelp.isNull(v_Text) )
        {
            v_FileName.append("_R.").append(v_Text.trim());
        }
        
        v_Text = ((JComboBox)     XJava.getObject("FamilyName")) .getSelectedItem().toString();
        if ( !JavaHelp.isNull(v_Text) ) 
        {
            v_FileName.append("_F.").append(v_Text.trim());
        }
        
        v_Text = ((JComboBox)     XJava.getObject("ColumnName")) .getSelectedItem().toString();
        if ( !JavaHelp.isNull(v_Text) ) 
        {
            v_FileName.append("_C.").append(v_Text.trim());
        }
        
        v_Text = ((JTextComponent)XJava.getObject("ColumnValue")).getText();
        if ( !JavaHelp.isNull(v_Text) ) 
        {
            v_FileName.append("_V.").append(v_Text.trim());
        }
    }
    else
    {
        v_FileName.append("_CCount.").append(v_RowIndexArr.length);
        v_FileName.append("_").append(Date.getNowTime().getFull_ID());
    }
    v_FileName.append(".txt");
    
    
    
    File         v_SaveFile    = new File(v_FileName.toString());
    JFileChooser v_FileChooser = new JFileChooser();
    v_FileChooser.setSelectedFile(v_SaveFile);
    
    int v_Result = v_FileChooser.showSaveDialog(this.getAppFrame());
    if ( v_Result == JFileChooser.APPROVE_OPTION )
    {
        v_SaveFile = v_FileChooser.getSelectedFile();
        
        this.writeContents(v_JTable ,v_RowIndexArr ,v_SaveFile);
    }
}
 
开发者ID:HY-ZhengWei,项目名称:HBaseClient,代码行数:72,代码来源:ExportActionListener.java


注:本文中的javax.swing.JTable.getSelectedRows方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。