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


Java JTable.getCellRect方法代码示例

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


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

示例1: computeFitText

import javax.swing.JTable; //导入方法依赖的package包/类
public static String computeFitText(JTable table, int rowIdx, int columnIdx, String text) {
    if(text == null) text = "";                                             // NOI18N
    if (text.length() <= VISIBLE_START_CHARS + 3) return text;

    FontMetrics fm = table.getFontMetrics(table.getFont());
    int width = table.getCellRect(rowIdx, columnIdx, false).width;

    String sufix = "...";                                                   // NOI18N
    int sufixLength = fm.stringWidth(sufix + " ");                          // NOI18N
    int desired = width - sufixLength;
    if (desired <= 0) return text;

    for (int i = 0; i <= text.length() - 1; i++) {
        String prefix = text.substring(0, i);
        int swidth = fm.stringWidth(prefix);
        if (swidth >= desired) {
            return prefix.length() > 0 ? prefix + sufix: text;
        }
    }
    return text;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:HistoryUtils.java

示例2: isCellEditable

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public boolean isCellEditable(EventObject anEvent) {
    if (anEvent.getSource() instanceof JTable) {
        JTable table = (JTable) anEvent.getSource();
        if (anEvent instanceof MouseEvent) {
            MouseEvent event = (MouseEvent) anEvent;
            Point p = event.getPoint();
            int row = table.rowAtPoint(p);
            int col = table.columnAtPoint(p);
            Rectangle rect = table.getCellRect(row, col, true);
            p.translate(-rect.x, -rect.y);
            System.out.println("isCellEditable("+anEvent+")");
            System.out.println("Point "+p+"in rectangle "+rect);
            if (p.x > rect.width - 24) {
                // last 24 points not editable
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:TableRendererTest.java

示例3: computeFitText

import javax.swing.JTable; //导入方法依赖的package包/类
private String computeFitText(JTable table, int rowIdx, int columnIdx,
        String text) {
    if (text == null) {
        text = ""; // NOI18N
    }
    if (text.length() <= 3) {
        return text;
    }

    FontMetrics fm = table.getFontMetrics(table.getFont());
    int width = table.getCellRect(rowIdx, columnIdx, false).width;

    String prefix = "...";                                          //NOI18N
    int sufixLength = fm.stringWidth(prefix + "  ");                 //NOI18
    int desired = width - sufixLength - 15;
    if (desired <= 0) {
        return text;
    }

    for (int i = 1; i <= text.length() - 1; i++) {
        String part = text.substring(text.length() - i, text.length());
        int swidth = fm.stringWidth(part);
        if (swidth >= desired) {
            return part.length() > 0 ? prefix + part + " " : text;  //NOI18N
        }
    }
    return text;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:ResultsOutlineCellRenderer.java

示例4: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent (
    JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column
) {
    JLabel c = (JLabel)defaultRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    
    if (value instanceof String) {
        Rectangle cellRect = table.getCellRect(row, column, false);
        String scCell = (String) value;
        Dimension d = new Dimension((int) cellRect.getWidth(), (int) cellRect.getHeight());
        if (panel == null)
            panel = new ShortcutCellPanel(scCell);
        panel.setText(scCell);
        panel.setSize(d);

        if (isSelected) {
            panel.setBgColor(table.getSelectionBackground());
            if (UIManager.getLookAndFeel ().getID ().equals ("GTK"))
                panel.setFgCOlor(table.getForeground(), true);
            else
                panel.setFgCOlor(table.getSelectionForeground(), true);
        } else {
            panel.setBgColor(c.getBackground());
            panel.setFgCOlor(c.getForeground(), false);
        }
        if (hasFocus) {
            panel.setBorder(c.getBorder());
        } else {
            panel.setBorder(null);
        }

        return panel;
    }
    else {
        return c;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:ButtonCellRenderer.java

示例5: showPopupMenu

import javax.swing.JTable; //导入方法依赖的package包/类
private boolean showPopupMenu(int row, int col, int x, int y) {
    JTable table = actionsTable;
    
    if (col != 1) {
        return false;
    }
    
    Object valueAt = table.getValueAt(row, col);
    ShortcutCellPanel scCell = (ShortcutCellPanel) table.getCellRenderer(row, col).getTableCellRendererComponent(table, valueAt, true, true, row, col);
    Rectangle cellRect = table.getCellRect(row, col, false);
    JButton button = scCell.getButton();
    if (x < 0  || x > (cellRect.x + cellRect.width - button.getWidth())) { //inside changeButton
        boolean isShortcutSet = scCell.getTextField().getText().length() != 0;
        final ShortcutPopupPanel panel = (ShortcutPopupPanel) popup.getComponents()[0];
        panel.setDisplayAddAlternative(isShortcutSet);
        panel.setRow(row);

        if (x == -1 || y == -1) {
            x = button.getX() + 1;
            y = button.getY() + 1;
        }
        panel.setCustomProfile(keymapModel.getMutableModel().isCustomProfile(keymapModel.getMutableModel().getCurrentProfile()));
        popup.show(table, x, y);
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                panel.requestFocus();
            }
        });
        popup.requestFocus();
        return true;
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:KeymapPanel.java

示例6: showWindow

import javax.swing.JTable; //导入方法依赖的package包/类
private void showWindow(JTable table, int row) {

		/* determine correct location */
		//TODO: throw away half of this rubbish
		Point offset = new Point();
		Point tablebase = table.getLocationOnScreen();
		Point framebase = owner.getLocationOnScreen();

		Rectangle cellRect = table.getCellRect(row, 0, true);
		int middle = table.getHeight() / 2;

		int deltax, deltay, width;

		deltay = tablebase.y - framebase.y;

		Component c = table.getParent();
		if (c instanceof JViewport) { //we are in a JScrollPane
			c = c.getParent();
			deltax = c.getLocationOnScreen().x - framebase.x;
			width = c.getWidth();
		} else {
			deltax = tablebase.x - framebase.x;
			width = table.getWidth();
		}

		offset.x = cellRect.x + deltax;

		if (cellRect.y > middle) {
			offset.y = cellRect.y - ldWindow.getHeight() + deltay;
		} else {
			offset.y = cellRect.y + cellRect.height + deltay;
		}
		//ldWindow.setBase(framebase);
		//ldWindow.setOffset(offset);

		ldWindow.centerWindow(width, ldWindow.getHeight());
		ldWindow.show();
	}
 
开发者ID:max6cn,项目名称:jmt,代码行数:39,代码来源:LDEditor.java

示例7: setLocationForTable

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * Sets the location to a point the table.
 *
 * @param table
 * @param location
 */
private void setLocationForTable(JTable table, Point location) {
    if (location != null) {
        Rectangle cellRect = table.getCellRect(table.getEditingRow(), table.getEditingColumn(), false);
        location.setLocation(cellRect.getLocation());
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:13,代码来源:RComponentFactory.java

示例8: mouseMoved

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public void mouseMoved(MouseEvent e) {
    JTable table = (JTable) e.getSource();
    Point pt = e.getPoint();
    int prev_row = this.row;
    int prev_col = this.col;
    this.row = table.rowAtPoint(pt);
    this.col = table.columnAtPoint(pt);
    if (this.row != prev_row || this.col != prev_col) {
        Rectangle r = table.getCellRect(this.row, this.col, false);
        r = r.union(table.getCellRect(prev_row, prev_col, false));
        table.repaint(r);
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:15,代码来源:LibrariesTable.java

示例9: pressCell

import javax.swing.JTable; //导入方法依赖的package包/类
/** Send a mouse pressed to a particular cell of a JTable */
protected static void pressCell(JTable tbl, int x, int y) throws Exception {
    Rectangle r = tbl.getCellRect(x, y, false);
    System.err.println("Pressing table at " + (r.x+5) + "," + r.y+5);
    press(tbl, r.x+5, r.y+5);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:ExtTestCase.java

示例10: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column ) {
    renderer.clear();
    Rectangle rect = table.getCellRect( row, column, true );
    renderer.setSize( rect.width, rect.height );
    if( value instanceof TabData ) {
        TabData tab = ( TabData ) value;
        String text = tab.getText();
        Icon icon = tab.getIcon();
        Color colBackground = isSelected ? table.getSelectionBackground() : table.getBackground();
        Color colForeground = isSelected ? table.getSelectionForeground() : table.getForeground();

        for( TabDecorator td : decorators ) {
            Color c = td.getBackground( tab, isSelected );
            if( null != c )
                colBackground = c;
            c = td.getForeground( tab, isSelected );
            if( null != c )
                colForeground = c;

            String s = td.getText( tab );
            if( null != s )
                text = s;

            Icon i = td.getIcon( tab );
            if( null != i ) {
                icon = i;
            }
        }
        renderer.label.setText( text );
        renderer.label.setIcon( icon );
        renderer.label.setFont( table.getFont() );
        renderer.setBackground( colBackground );
        renderer.label.setForeground( colForeground );
        renderer.tabData = tab;
        renderer.isSelected = isSelected;

        if( table instanceof TabTable ) {
            TabTable tabTable = ( TabTable ) table;
            if( isClosable(tab) ) {
                boolean inCloseButton = tabTable.isCloseButtonHighlighted( row, column );
                renderer.closeButton.setVisible( true );
                renderer.closeButton.getModel().setRollover( inCloseButton );
                renderer.closeButton.getModel().setArmed( inCloseButton );
            } else {
                renderer.closeButton.setVisible( false );
            }
        }
    }
    return renderer;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:52,代码来源:TabDataRenderer.java

示例11: isVisible

import javax.swing.JTable; //导入方法依赖的package包/类
private boolean isVisible(JTable table, int row, int col) {
    Rectangle visibleRect = table.getVisibleRect();
    Rectangle cellRect = table.getCellRect(row, col, false);
    return SwingUtilities.isRectangleContainingRectangle(visibleRect, cellRect);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:6,代码来源:JTableCellJavaElement.java


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