本文整理匯總了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);
}
}
}
}