本文整理汇总了Java中javax.swing.JComponent.getBounds方法的典型用法代码示例。如果您正苦于以下问题:Java JComponent.getBounds方法的具体用法?Java JComponent.getBounds怎么用?Java JComponent.getBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JComponent
的用法示例。
在下文中一共展示了JComponent.getBounds方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scroll
import javax.swing.JComponent; //导入方法依赖的package包/类
/**
* Scroll to specified location. e.g.
* <tt>scroll(component, LEFT, BOTTOM);</tt>.
*
* @param c
* JComponent to scroll.
* @param horizontal
* Horizontal location. Should take the value: LEFT, HCENTER or
* RIGHT.
* @param vertical
* Vertical location. Should take the value: TOP, VCENTER or
* BOTTOM.
*/
public static void scroll(JComponent c, int horizontal, int vertical){
Rectangle visible=c.getVisibleRect();
Rectangle bounds=c.getBounds();
switch(vertical){
case TOP:
visible.y=0;
break;
case VCENTER:
visible.y=(bounds.height-visible.height)/2;
break;
case BOTTOM:
visible.y=bounds.height-visible.height+OFFSET;
break;
}
switch(horizontal){
case LEFT:
visible.x=0;
break;
case HCENTER:
visible.x=(bounds.width-visible.width)/2;
break;
case RIGHT:
visible.x=bounds.width-visible.width+OFFSET;
break;
}
// When scrolling to bottom or right of viewport, add an OFFSET value.
// This is because without this certain components (e.g. JTable) would
// not scroll right to the bottom (presumably the bounds calculation
// doesn't take the table header into account. It doesn't matter if
// OFFSET is a huge value (e.g. 10000) - the scrollRectToVisible method
// still works correctly.
c.scrollRectToVisible(visible);
}
示例2: paintOverallBorder
import javax.swing.JComponent; //导入方法依赖的package包/类
/**
* Paints lower border, bottom line, separating tabs from content
*/
protected void paintOverallBorder(Graphics g, JComponent c) {
if (isGenericUI) {
return;
}
Rectangle r = c.getBounds();
g.setColor(UIManager.getColor("InternalFrame.borderDarkShadow")); //NOI18N
g.drawLine(0, r.height - 1, r.width - 1, r.height - 1);
}
示例3: paintBottomBorder
import javax.swing.JComponent; //导入方法依赖的package包/类
/**
* Paints bottom "activation" line
*/
private void paintBottomBorder(Graphics g, JComponent c) {
Color color = isActive() ? getActBgColor() : getInactBgColor();
g.setColor(color);
Rectangle bounds = c.getBounds();
g.fillRect(1, bounds.height - 3, bounds.width - 1, 2);
g.setColor(getBorderShadow());
g.drawLine(1, bounds.height - 1, bounds.width - 1, bounds.height - 1);
}
示例4: configureBalloon
import javax.swing.JComponent; //导入方法依赖的package包/类
private static void configureBalloon( Balloon balloon, JLayeredPane pane, JComponent ownerComp ) {
Rectangle ownerCompBounds = ownerComp.getBounds();
ownerCompBounds = SwingUtilities.convertRectangle( ownerComp.getParent(), ownerCompBounds, pane );
int paneWidth = pane.getWidth();
int paneHeight = pane.getHeight();
Dimension balloonSize = balloon.getPreferredSize();
balloonSize.height += Balloon.ARC;
//first try lower right corner
if( ownerCompBounds.x + ownerCompBounds.width + balloonSize.width < paneWidth
&&
ownerCompBounds.y + ownerCompBounds.height + balloonSize.height + Balloon.ARC < paneHeight ) {
balloon.setArrowLocation( GridBagConstraints.SOUTHEAST );
balloon.setBounds( ownerCompBounds.x+ownerCompBounds.width-Balloon.ARC/2,
ownerCompBounds.y+ownerCompBounds.height, balloonSize.width+Balloon.ARC, balloonSize.height );
//upper right corner
} else if( ownerCompBounds.x + ownerCompBounds.width + balloonSize.width < paneWidth
&&
ownerCompBounds.y - balloonSize.height - Balloon.ARC > 0 ) {
balloon.setArrowLocation( GridBagConstraints.NORTHEAST );
balloon.setBounds( ownerCompBounds.x+ownerCompBounds.width-Balloon.ARC/2,
ownerCompBounds.y-balloonSize.height, balloonSize.width+Balloon.ARC, balloonSize.height );
//lower left corner
} else if( ownerCompBounds.x - balloonSize.width > 0
&&
ownerCompBounds.y + ownerCompBounds.height + balloonSize.height + Balloon.ARC < paneHeight ) {
balloon.setArrowLocation( GridBagConstraints.SOUTHWEST );
balloon.setBounds( ownerCompBounds.x-balloonSize.width+Balloon.ARC/2,
ownerCompBounds.y+ownerCompBounds.height, balloonSize.width+Balloon.ARC, balloonSize.height );
//upper left corent
} else {
balloon.setArrowLocation( GridBagConstraints.NORTHWEST );
balloon.setBounds( ownerCompBounds.x-balloonSize.width/*+Balloon.ARC/2*/,
ownerCompBounds.y-balloonSize.height, balloonSize.width+Balloon.ARC, balloonSize.height );
}
}