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