Java Code Examples for javax.swing.JComponent.getBounds()

The following are Jave code examples for showing how to use getBounds() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OpenGL-Bullet-engine   File: ScrollUtil.java   View Source Code Vote up 5 votes
/**
 * 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);
}
 
Example 2
Project: incubator-netbeans   File: WinClassicViewTabDisplayerUI.java   View Source Code Vote up 5 votes
/**
 * 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);
}
 
Example 3
Project: incubator-netbeans   File: MetalViewTabDisplayerUI.java   View Source Code Vote up 5 votes
/**
 * 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);
}
 
Example 4
Project: incubator-netbeans   File: BalloonManager.java   View Source Code Vote up 4 votes
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 );
    }
}
 
Example 5
Project: incubator-netbeans   File: BalloonManager.java   View Source Code Vote up 4 votes
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 );
    }
}