本文整理匯總了Java中javax.swing.JViewport.getWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java JViewport.getWidth方法的具體用法?Java JViewport.getWidth怎麽用?Java JViewport.getWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JViewport
的用法示例。
在下文中一共展示了JViewport.getWidth方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: resize
import javax.swing.JViewport; //導入方法依賴的package包/類
/**
* Forces the table to resize given column.
*/
private void resize(int newWidth, JTable table) {
int oldWidth = getWidth();
JTableHeader header = table.getTableHeader();
if (header == null) {
return;
}
header.setResizingColumn(this);
final int oldMin = getMinWidth();
final int oldMax = getMaxWidth();
setMinWidth(newWidth);
setMaxWidth(newWidth);
setWidth(newWidth);
// The trick is to restore the original values
// after the table has be layouted. During layout this column
// has fixed width (by setting min==max==preffered)
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setMinWidth(oldMin);
setMaxWidth(oldMax);
}
});
Container container;
if ((header.getParent() == null) ||
((container = header.getParent().getParent()) == null) ||
!(container instanceof JScrollPane)) {
header.setResizingColumn(null);
return;
}
if (!container.getComponentOrientation().isLeftToRight() &&
! header.getComponentOrientation().isLeftToRight()) {
if (table != null) {
JViewport viewport = ((JScrollPane)container).getViewport();
int viewportWidth = viewport.getWidth();
int diff = newWidth - oldWidth;
int newHeaderWidth = table.getWidth() + diff;
/* Resize a table */
Dimension tableSize = table.getSize();
tableSize.width += diff;
table.setSize(tableSize);
/* If this table is in AUTO_RESIZE_OFF mode and
* has a horizontal scrollbar, we need to update
* a view's position.
*/
if ((newHeaderWidth >= viewportWidth) &&
(table.getAutoResizeMode() == JTable.AUTO_RESIZE_OFF)) {
Point p = viewport.getViewPosition();
p.x = Math.max(0, Math.min(newHeaderWidth - viewportWidth, p.x + diff));
viewport.setViewPosition(p);
}
}
}
header.setResizingColumn(null);
}