Java Code Examples for javax.swing.JTable#setCursor()

The following examples show how to use javax.swing.JTable#setCursor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TableRowTransferHandler.java    From PyramidShader with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean importData(TransferHandler.TransferSupport info) {
    JTable target = (JTable) info.getComponent();
    JTable.DropLocation dl = (JTable.DropLocation) info.getDropLocation();
    int dropIndex = dl.getRow();
    int max = table.getModel().getRowCount();
    if (dropIndex < 0 || dropIndex > max) {
        dropIndex = max;
    }
    target.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    try {
        Integer rowFrom = (Integer) info.getTransferable().getTransferData(localObjectFlavor);
        if (rowFrom != -1 && rowFrom != dropIndex) {
            ((Reorderable)table.getModel()).reorder(rowFrom, dropIndex);
            if (dropIndex > rowFrom) {
                dropIndex--;
            }
            target.getSelectionModel().addSelectionInterval(dropIndex, dropIndex);
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
Example 2
Source File: UmbelSearchConceptSelector.java    From wandora with GNU General Public License v3.0 6 votes vote down vote up
private void updateDataTable() {
    dataTable = new JTable();
    dataTable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    if(data != null) {
        dataModel = new UmbelConceptTableModel(data);
        dataTable.setModel(dataModel);
        dataTable.setRowSorter(new TableRowSorter(dataModel));

        dataTable.setColumnSelectionAllowed(false);
        dataTable.setRowSelectionAllowed(true);
        dataTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

        TableColumn column = null;
        for (int i=0; i < dataTable.getColumnCount(); i++) {
            column = dataTable.getColumnModel().getColumn(i);
            column.setPreferredWidth(dataModel.getColumnWidth(i));
        }
        tableScrollPane.setViewportView(dataTable);
    }
}
 
Example 3
Source File: TableRowTransferHandler.java    From RobotBuilder with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean importData(TransferHandler.TransferSupport info) {
    JTable target = (JTable) info.getComponent();
    JTable.DropLocation dl = (JTable.DropLocation) info.getDropLocation();
    int index = dl.getRow();
    int max = table.getModel().getRowCount();
    if (index < 0 || index > max) {
        index = max;
    }
    target.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    try {
        Integer rowFrom = (Integer) info.getTransferable().getTransferData(localObjectFlavor);
        if (rowFrom != -1 && rowFrom != index) {
            Vector<Object> rowData = (Vector) getTableModel().getDataVector().get(rowFrom);
            getTableModel().removeRow(rowFrom);
            getTableModel().insertRow(index, rowData);
            if (index > rowFrom) {
                index--;
            }
            target.getSelectionModel().addSelectionInterval(index, index);
            return true;
        }
    } catch (UnsupportedFlavorException | IOException e) {
        e.printStackTrace();
    }
    return false;
}
 
Example 4
Source File: MaianaImportPanel.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
public void setTopicMapsList() {
    if(getApiKey() != null) {
        try {
            JSONObject list = MaianaUtils.listAvailableTopicMaps(getApiEndPoint(), getApiKey());
            if(list.has("msg")) {
                WandoraOptionPane.showMessageDialog(window, list.getString("msg"), "API says", WandoraOptionPane.WARNING_MESSAGE);
                //System.out.println("REPLY:"+list.toString());
            }

            if(list.has("data")) {
                mapTable = new JTable();
                mapTable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                if(list != null) {
                    JSONArray datas = list.getJSONArray("data");
                    TopicMapsTableModel myModel = new TopicMapsTableModel(datas);
                    mapTable.setModel(myModel);
                    mapTable.setRowSorter(new TableRowSorter(myModel));

                    mapTable.setColumnSelectionAllowed(false);
                    mapTable.setRowSelectionAllowed(true);
                    mapTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
                    
                    TableColumn column = null;
                    for (int i=0; i < mapTable.getColumnCount(); i++) {
                        column = mapTable.getColumnModel().getColumn(i);
                        column.setPreferredWidth(myModel.getColumnWidth(i));
                    }
                    tableScrollPane.setViewportView(mapTable);
                }
            }
        }
        catch(Exception e) {
            Wandora.getWandora().displayException("Exception '"+e.getMessage()+"' occurred while getting the list of topic maps.", e);
        }
    }


}
 
Example 5
Source File: HyperlinkCellRenderer.java    From littleluck with Apache License 2.0 4 votes vote down vote up
@Override
public void mouseMoved(MouseEvent event) {
    // This should only be called if underlineOnRollover is true
    JTable table = (JTable) event.getSource();

    // Locate the table cell under the event location
    int oldHitColumnIndex = hitColumnIndex;
    int oldHitRowIndex = hitRowIndex;

    checkIfPointInsideHyperlink(event.getPoint());

    if (hitRowIndex != oldHitRowIndex ||
            hitColumnIndex != oldHitColumnIndex) {
        if (hitRowIndex != -1) {
            if (tableCursor == null) {
                tableCursor = table.getCursor();
            }
            table.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        } else {
            table.setCursor(tableCursor);
        }

        // repaint the cells affected by rollover
        Rectangle repaintRect;
        if (hitRowIndex != -1 && hitColumnIndex != -1) {
            // we need to repaint new cell with rollover underline
            // cellRect already contains rect of hit cell
            if (oldHitRowIndex != -1 && oldHitColumnIndex != -1) {
                // we also need to repaint previously underlined hyperlink cell
                // to remove the underline
                repaintRect = cellRect.union(
                        table.getCellRect(oldHitRowIndex, oldHitColumnIndex, false));
            } else {
                // we don't have a previously underlined hyperlink, so just repaint new one'
                repaintRect = table.getCellRect(hitRowIndex, hitColumnIndex, false);
            }
        } else {
            // we just need to repaint previously underlined hyperlink cell
            //to remove the underline
            repaintRect = table.getCellRect(oldHitRowIndex, oldHitColumnIndex, false);
        }
        table.repaint(repaintRect);
    }

}
 
Example 6
Source File: HyperlinkCellRenderer.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
@Override
public void mouseMoved(MouseEvent event) {
    // This should only be called if underlineOnRollover is true
    JTable table = (JTable) event.getSource();

    // Locate the table cell under the event location
    int oldHitColumnIndex = hitColumnIndex;
    int oldHitRowIndex = hitRowIndex;

    checkIfPointInsideHyperlink(event.getPoint());

    if (hitRowIndex != oldHitRowIndex ||
            hitColumnIndex != oldHitColumnIndex) {
        if (hitRowIndex != -1) {
            if (tableCursor == null) {
                tableCursor = table.getCursor();
            }
            table.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        } else {
            table.setCursor(tableCursor);
        }

        // repaint the cells affected by rollover
        Rectangle repaintRect;
        if (hitRowIndex != -1 && hitColumnIndex != -1) {
            // we need to repaint new cell with rollover underline
            // cellRect already contains rect of hit cell
            if (oldHitRowIndex != -1 && oldHitColumnIndex != -1) {
                // we also need to repaint previously underlined hyperlink cell
                // to remove the underline
                repaintRect = cellRect.union(
                        table.getCellRect(oldHitRowIndex, oldHitColumnIndex, false));
            } else {
                // we don't have a previously underlined hyperlink, so just repaint new one'
                repaintRect = table.getCellRect(hitRowIndex, hitColumnIndex, false);
            }
        } else {
            // we just need to repaint previously underlined hyperlink cell
            //to remove the underline
            repaintRect = table.getCellRect(oldHitRowIndex, oldHitColumnIndex, false);
        }
        table.repaint(repaintRect);
    }

}