如何在JTable中选择多行进行拖放?

时间:2016-07-27 10:06:41

标签: java jtable

我有一个JTable,其中表允许我最初一次只选择并拖动一行,然后它允许我从第二次选择并拖动多行,如何让它允许我选择第一次也是多行。

     private void initialize()
     {
        propertyTable = GUI.getTable();
        Vector columnVector = new Vector();
        columnVector.addElement("Property Name");
        columnVector.addElement("Alias Name");
        propertyTableModel = new PropertyTableModel(getEmptyDataVector(),columnVector);

        propertyTable.setModel(propertyTableModel);
        propertyTable.getSelectionModel().addListSelectionListener(this);

        propertyTable.getTableHeader().setReorderingAllowed(false);
        propertyTable.getTableHeader().setBackground(new Color(47,81,121));
        propertyTable.getTableHeader().setForeground(Color.white);

        propertyTable.setDragEnabled(true);
        propertyTable.setTransferHandler(new TransferHandler());


        propertyColumn = propertyTable.getColumnModel().getColumn(0);
        aliasColumn = propertyTable.getColumnModel().getColumn(1);
        propertyColumn.setCellRenderer(new PropertyAliasColumnTableCellRenderer());
        aliasColumn.setCellRenderer(new PropertyAliasColumnTableCellRenderer());

        tablePanel = createPropertyNamesTablePanel();

        setLayout(new BorderLayout(5,5));
        add(tablePanel ,"Center");
    }


   private Vector getEmptyDataVector()
   {
       Vector dataVector = new Vector();
       Vector rowVector = new Vector();
       rowVector.addElement("");
       rowVector.addElement("");
       dataVector.addElement(rowVector);
       return dataVector;
   }

0 个答案:

没有答案