Example usage for javax.swing JTable getCellRect

List of usage examples for javax.swing JTable getCellRect

Introduction

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

Prototype

public Rectangle getCellRect(int row, int column, boolean includeSpacing) 

Source Link

Document

Returns a rectangle for the cell that lies at the intersection of row and column.

Usage

From source file:MainClass.java

public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
        int column) {
    if (value == null) {
        return this;
    }/*from   w ww.jav a  2 s .c  o m*/
    if (value instanceof Volume) {
        setValue(((Volume) value).getVolume());
    } else {
        setValue(0);
    }
    table.setRowSelectionInterval(row, row);
    table.setColumnSelectionInterval(column, column);
    originalValue = getValue();
    editing = true;
    Point p = table.getLocationOnScreen();
    Rectangle r = table.getCellRect(row, column, true);
    helper.setLocation(r.x + p.x + getWidth() - 50, r.y + p.y + getHeight());
    helper.setVisible(true);
    return this;
}

From source file:de.mendelson.comm.as2.client.AS2Gui.java

/**
 * Scrolls to an entry of the passed table
 *
 * @param table Table to to scroll in//from  w w w  .  j  av a  2s  . c o m
 * @param row Row to ensure visibility
 */
private void makeRowVisible(JTable table, int row) {
    if (table.getColumnCount() == 0) {
        return;
    }
    if (row < 0 || row >= table.getRowCount()) {
        throw new IllegalArgumentException("Requested ensure visible of row " + String.valueOf(row)
                + ", table has only " + table.getRowCount() + " rows.");
    }
    Rectangle visible = table.getVisibleRect();
    Rectangle cell = table.getCellRect(row, 0, true);
    if (cell.y < visible.y) {
        visible.y = cell.y;
        table.scrollRectToVisible(visible);
    } else if (cell.y + cell.height > visible.y + visible.height) {
        visible.y = cell.y + cell.height - visible.height;
        table.scrollRectToVisible(visible);
    }
}

From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java

public static boolean isTextFit(JComponent renderer, JTable table, int row, int column, String text,
        int padding) {
    return isTextFit(renderer, table.getCellRect(row, column, false).width - padding, text);
}

From source file:org.nuclos.client.ui.collect.result.ResultController.java

private ListSelectionListener newListSelectionListener(final JTable tblResult) {
    return new ListSelectionListener() {
        @Override/*from   w w  w .ja  v  a 2 s. c o m*/
        public void valueChanged(ListSelectionEvent ev) {
            try {
                final ListSelectionModel lsm = (ListSelectionModel) ev.getSource();

                final CollectStateModel<?> clctstatemodel = clctctl.getCollectStateModel();
                if (clctstatemodel.getOuterState() == CollectState.OUTERSTATE_RESULT) {
                    final int iResultMode = CollectStateModel.getResultModeFromSelectionModel(lsm);
                    if (iResultMode != clctctl.getCollectStateModel().getResultMode()) {
                        clctctl.setCollectState(CollectState.OUTERSTATE_RESULT, iResultMode);
                    }
                }

                if (!ev.getValueIsAdjusting()) {
                    // Autoscroll selection. It's okay to do that here rather than in the CollectStateListener.
                    if (!lsm.isSelectionEmpty() && tblResult.getAutoscrolls()) {
                        // ensure that the last selected row is visible:
                        final int iRowIndex = lsm.getLeadSelectionIndex();
                        final int iColIndex = tblResult.getSelectedColumn();
                        final Rectangle rectCell = tblResult.getCellRect(iRowIndex,
                                iColIndex != -1 ? iColIndex : 0, true);
                        if (rectCell != null) {
                            tblResult.scrollRectToVisible(rectCell);
                        }
                    }
                }
            } catch (CommonBusinessException ex) {
                Errors.getInstance().showExceptionDialog(clctctl.getTab(), ex);
            }
        } // valueChanged
    };
}

From source file:org.piraso.ui.api.util.JTableUtils.java

public static void scrollTo(JTable[] tables, int rowNum) {
    if (ArrayUtils.isNotEmpty(tables)) {
        for (JTable table : tables) {
            if (table == null)
                continue;

            table.scrollRectToVisible(table.getCellRect(rowNum, 1, true));
        }//w w  w  .  ja v  a  2s  .c  o m
    }
}

From source file:org.yccheok.jstock.gui.JTableUtilities.java

public static void scrollToVisible(JTable table, int rowIndex, int vColIndex) {
    if (!(table.getParent() instanceof JViewport)) {
        return;//  ww  w . j a v a2  s.  com
    }

    JViewport viewport = (JViewport) table.getParent();

    // This rectangle is relative to the table where the
    // northwest corner of cell (0,0) is always (0,0).
    Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);

    // The location of the viewport relative to the table
    Point pt = viewport.getViewPosition();

    // Translate the cell location so that it is relative
    // to the view, assuming the northwest corner of the
    // view is (0,0)
    rect.setLocation(rect.x - pt.x, rect.y - pt.y);

    // Scroll the area into view
    viewport.scrollRectToVisible(rect);
}

From source file:pipeline.parameter_cell_views.FloatSlider.java

@SuppressWarnings("unused")
@Override/*from w ww .j  av a 2  s . c om*/
public Component getRendererOrEditorComponent(JTable table, @NonNull Object value, boolean isSelected,
        boolean hasFocus, int row, int column, boolean rendererCalled) {

    if (table != null) {
        Dimension d = getPreferredSize();
        d.width = table.getColumnModel().getColumn(column).getWidth();
        setSize(d);
    }

    if (currentParameter != null) {
        currentParameter.removeListener(this);
    }

    currentParameter = (FloatParameter) value;
    /*if (value == null) {
       slider.setEnabled(true);
       textMinimum.setEditable(true);
       textMaximum.setEditable(true);
       currentTextValue.setEditable(true);
       return this;
    }*/
    currentParameter.addGUIListener(this);
    currentParameter.validateRange();

    silenceUpdate = true;
    evenTableRow = (row % 2 == 0);
    setOpaque(true);
    if (evenTableRow)
        this.setBackground(Utils.COLOR_FOR_EVEN_ROWS);
    else
        this.setBackground(Utils.COLOR_FOR_ODD_ROWS);

    if (true) {// rendererCalled
        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.BOTH;

        // For some strange reason, the slider doesn't get updated properly upon resizes
        // (only in the renderer, not the editor)
        // workaround is to remove it and re-create it

        remove(slider);
        readInParameterValues();
        slider = new JSlider((int) (minimum * 100f), (int) (maximum * 100f), (int) (currentValue * 100f));

        c.gridx = 0;
        c.gridy = 0;
        c.weighty = 1.0;
        c.weightx = 1.0;
        c.gridwidth = 3;
        add(slider, c);
        slider.addChangeListener(new sliderListener());
    } else {
        if (table != null)
            slider.setBounds(table.getCellRect(row, column, false));
        slider.updateUI();
    }

    updateDisplay();

    if (table != null) {
        int height_wanted = (int) getPreferredSize().getHeight();
        if (height_wanted > table.getRowHeight(row))
            table.setRowHeight(row, height_wanted);
    }

    silenceUpdate = false;
    return this;

}

From source file:pipeline.parameter_cell_views.IntRangeSlider.java

@Override
protected Component getRendererOrEditorComponent(JTable table0, @NonNull Object value, boolean isSelected,
        boolean hasFocus, int row, int column, boolean rendererCalled) {

    if (currentParameter != null) {
        currentParameter.removeListener(this);
    }/*from w w  w.j  a v a  2 s .co m*/

    currentParameter = (IntRangeParameter) value;
    currentParameter.addGUIListener(this);

    table = table0;
    tableRow = row;

    evenTableRow = (row % 2 == 0);
    setOpaque(true);
    if (evenTableRow) {
        this.setBackground(Utils.COLOR_FOR_EVEN_ROWS);
    } else
        this.setBackground(Utils.COLOR_FOR_ODD_ROWS);
    textValueFrame.setBackground(getBackground());

    updateValues();

    parameterName.setText(currentParameter.getParamNameDescription()[0]);
    parameterName.setVisible(!currentParameter.getParamNameDescription()[0].equals(""));
    textMinimum.setEditable(currentParameter.editable()[0]);
    textMaximum.setEditable(currentParameter.editable()[1]);
    this.setToolTipText(currentParameter.getParamNameDescription()[1]);
    int height_wanted = (int) getPreferredSize().getHeight();
    if (height_wanted > table0.getRowHeight(row))
        table0.setRowHeight(row, height_wanted);
    if (!rendererCalled) {
        slider.setBounds(table0.getCellRect(row, column, false));
        slider.updateUI();
    }

    silenceUpdate = false;
    return this;
}

From source file:pl.otros.logview.api.gui.LogViewPanelWrapper.java

private void addRowAutoScroll() {
    dataTableModel.addTableModelListener(e -> {
        if (follow.isSelected() && e.getType() == TableModelEvent.INSERT) {
            final Runnable r = () -> {
                try {
                    JTable table = logViewPanel.getTable();
                    int row = table.getRowCount() - 1;
                    if (row > 0) {
                        Rectangle rect = table.getCellRect(row, 0, true);
                        table.scrollRectToVisible(rect);
                        table.clearSelection();
                        table.setRowSelectionInterval(row, row);
                    }//from   w w  w.j  a v  a 2 s. c  o m
                } catch (IllegalArgumentException iae) {
                    // ignore..out of bounds
                    iae.printStackTrace();
                }
            };
            // Wait for JViewPort size update
            // TODO Find way to invoke this listener after viewport is notified about changes
            Runnable r2 = () -> {
                try {
                    Thread.sleep(300);
                } catch (InterruptedException ignore) {
                }
                SwingUtilities.invokeLater(r);
            };
            new Thread(r2).start();
        }
    });
}

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;/*ww w.ja v  a2s  . c o m*/
    }
    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);
    }
}