Example usage for javax.swing JTable convertRowIndexToView

List of usage examples for javax.swing JTable convertRowIndexToView

Introduction

In this page you can find the example usage for javax.swing JTable convertRowIndexToView.

Prototype

public int convertRowIndexToView(int modelRowIndex) 

Source Link

Document

Maps the index of the row in terms of the TableModel to the view.

Usage

From source file:me.mayo.telnetkek.MainPanel.java

public final void updatePlayerList(final String selectedPlayerName) {
    EventQueue.invokeLater(() -> {
        playerListTableModel.fireTableDataChanged();

        MainPanel.this.txtNumPlayers.setText("" + playerList.size());

        if (selectedPlayerName != null) {
            final JTable table = MainPanel.this.tblPlayers;
            final ListSelectionModel selectionModel = table.getSelectionModel();

            playerList.stream().filter((player) -> (player.getName().equals(selectedPlayerName)))
                    .forEach((player) -> {
                        selectionModel.setSelectionInterval(0,
                                table.convertRowIndexToView(playerList.indexOf(player)));
                    });//from   ww  w . j a v a 2 s . c o m
        }
    });
}

From source file:pl.otros.logview.gui.actions.search.SearchAction.java

public void performSearch(String text, SearchDirection direction) {
    StatusObserver statusObserver = getOtrosApplication().getStatusObserver();
    JTabbedPane jTabbedPane = getOtrosApplication().getJTabbedPane();
    LogViewPanelWrapper lvPanel = (LogViewPanelWrapper) jTabbedPane.getSelectedComponent();
    if (lvPanel == null) {
        return;/*www .  ja  v a 2s .c om*/
    }
    JTable table = lvPanel.getLogViewPanel().getTable();

    NextRowProvider nextRowProvider = NextRowProviderFactory.getFilteredTableRow(table, direction);
    SearchContext context = new SearchContext();
    context.setDataTableModel(lvPanel.getDataTableModel());
    SearchMatcher searchMatcher = null;
    String confKey = null;
    if (SearchMode.STRING_CONTAINS.equals(searchMode)) {
        searchMatcher = new StringContainsSearchMatcher(text);
        confKey = ConfKeys.SEARCH_LAST_STRING;
    } else if (SearchMode.REGEX.equals(searchMode)) {
        try {
            searchMatcher = new RegexMatcher(text);
            confKey = ConfKeys.SEARCH_LAST_REGEX;
        } catch (Exception e) {
            statusObserver.updateStatus("Error in regular expression: " + e.getMessage(),
                    StatusObserver.LEVEL_ERROR);
            return;
        }
    } else if (SearchMode.QUERY.equals(searchMode)) {
        QueryAcceptCondition acceptCondition;
        try {
            acceptCondition = new QueryAcceptCondition(text);
            searchMatcher = new AcceptConditionSearchMatcher(acceptCondition);
            confKey = ConfKeys.SEARCH_LAST_QUERY;
        } catch (RuleException e) {
            statusObserver.updateStatus("Wrong query rule: " + e.getMessage(), StatusObserver.LEVEL_ERROR);
            return;

        }
    }
    updateList(confKey, getOtrosApplication().getConfiguration(), text);
    DefaultComboBoxModel model = (DefaultComboBoxModel) getOtrosApplication().getSearchField().getModel();
    model.removeElement(text);
    model.insertElementAt(text, 0);
    model.setSelectedItem(text);
    int maxCount = getOtrosApplication().getConfiguration().getInt(ConfKeys.SEARCH_LAST_COUNT, 30);
    while (model.getSize() > maxCount) {
        model.removeElementAt(model.getSize() - 1);
    }

    context.setSearchMatcher(searchMatcher);
    SearchResult searchNext = searchEngine.searchNext(context, nextRowProvider);
    if (searchNext.isFound()) {
        int row = table.convertRowIndexToView(searchNext.getRow());
        Rectangle rect = table.getCellRect(row, 0, true);
        table.scrollRectToVisible(rect);
        table.clearSelection();
        table.setRowSelectionInterval(row, row);
        statusObserver.updateStatus(String.format("Found at row %d", row), StatusObserver.LEVEL_NORMAL);
        if (markFound) {
            lvPanel.getDataTableModel().markRows(markerColors, table.convertRowIndexToModel(row));
        }

        scrollToSearchResult(
                searchMatcher.getFoundTextFragments(
                        lvPanel.getDataTableModel().getLogData(table.convertRowIndexToModel(row))),
                lvPanel.getLogViewPanel().getLogDetailTextArea());
    } else {
        statusObserver.updateStatus(String.format("\"%s\" not found", text), StatusObserver.LEVEL_WARNING);
    }
}