本文整理汇总了Java中javax.swing.JViewport.getHeight方法的典型用法代码示例。如果您正苦于以下问题:Java JViewport.getHeight方法的具体用法?Java JViewport.getHeight怎么用?Java JViewport.getHeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JViewport
的用法示例。
在下文中一共展示了JViewport.getHeight方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExtentBounds
import javax.swing.JViewport; //导入方法依赖的package包/类
/** Get position of the component extent. The (x, y) are set to (0, 0) if there's
* no viewport or (-x, -y) if there's one.
*/
public Rectangle getExtentBounds(Rectangle r) {
if (r == null) {
r = new Rectangle();
}
if (component != null) {
JViewport port = getParentViewport();
if (port != null) {
Point p = port.getViewPosition();
r.width = port.getWidth();
r.height = port.getHeight();
r.x = p.x;
r.y = p.y;
} else { // no viewport
r.setBounds(component.getVisibleRect());
}
}
return r;
}
示例2: AtualizaTamanho
import javax.swing.JViewport; //导入方法依赖的package包/类
public void AtualizaTamanho() {
int pos = alturaTexto;
if (pos > getHeight()) {
JViewport jvp = ((JViewport) getParent());
setSize(jvp.getExtentSize().width, pos + 2);
setPreferredSize(getSize());
if (alturaTexto > jvp.getHeight()) {
jvp.setViewPosition(new Point(espaco, getHeight()));
}
repaint();
}
}
示例3: mouseClicked
import javax.swing.JViewport; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
JTableHeader header = (JTableHeader) e.getSource();
TableColumn tableColumn = getResizingColumn(header, e.getPoint());
if (tableColumn == null) {
return;
}
JTable table = header.getTable();
if ((e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK) {
if (table instanceof ExtendedJTable) {
((ExtendedJTable) table).pack();
e.consume();
}
} else {
int col = header.getColumnModel().getColumnIndex(tableColumn.getIdentifier());
int width = (int) header.getDefaultRenderer()
.getTableCellRendererComponent(table, tableColumn.getIdentifier(), false, false, -1, col)
.getPreferredSize().getWidth();
int firstRow = 0;
int lastRow = table.getRowCount();
if (table instanceof ExtendedJTable) {
ExtendedJScrollPane scrollPane = ((ExtendedJTable) table).getExtendedScrollPane();
if (scrollPane != null) {
JViewport viewport = scrollPane.getViewport();
Rectangle viewRect = viewport.getViewRect();
if (viewport.getHeight() < table.getHeight()) {
firstRow = table.rowAtPoint(new Point(0, viewRect.y));
firstRow = Math.max(0, firstRow);
lastRow = table.rowAtPoint(new Point(0, viewRect.y + viewRect.height - 1));
lastRow = Math.min(lastRow, table.getRowCount());
}
}
}
for (int row = firstRow; row < lastRow; row++) {
int preferedWidth = (int) table.getCellRenderer(row, col)
.getTableCellRendererComponent(table, table.getValueAt(row, col), false, false, row, col)
.getPreferredSize().getWidth();
width = Math.max(width, preferedWidth);
}
header.setResizingColumn(tableColumn); // this line is very important
tableColumn.setWidth(width + table.getIntercellSpacing().width);
e.consume();
}
}
}
示例4: packColumn
import javax.swing.JViewport; //导入方法依赖的package包/类
public void packColumn() {
JTableHeader header = getTableHeader();
if (header != null) {
int col = getSelectedColumn();
if (col >= 0) {
TableColumn tableColumn = header.getColumnModel().getColumn(col);
if (tableColumn != null) {
int width = (int) header.getDefaultRenderer()
.getTableCellRendererComponent(this, tableColumn.getIdentifier(), false, false, -1, col)
.getPreferredSize().getWidth();
int firstRow = 0;
int lastRow = getRowCount();
ExtendedJScrollPane scrollPane = getExtendedScrollPane();
if (scrollPane != null) {
JViewport viewport = scrollPane.getViewport();
Rectangle viewRect = viewport.getViewRect();
if (viewport.getHeight() < getHeight()) {
firstRow = rowAtPoint(new Point(0, viewRect.y));
firstRow = Math.max(0, firstRow);
lastRow = rowAtPoint(new Point(0, viewRect.y + viewRect.height - 1));
lastRow = Math.min(lastRow, getRowCount());
}
}
for (int row = firstRow; row < lastRow; row++) {
int preferedWidth = (int) getCellRenderer(row, col)
.getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col)
.getPreferredSize().getWidth();
width = Math.max(width, preferedWidth);
}
header.setResizingColumn(tableColumn); // this line is very important
tableColumn.setWidth(width + getIntercellSpacing().width);
}
}
}
}