Java Code Examples for java.awt.Component#getBounds()

The following examples show how to use java.awt.Component#getBounds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WPrinterJob.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void init(Component parent, String  title, String message,
                  String buttonText) {
    Panel p = new Panel();
    add("Center", new Label(message));
    Button btn = new Button(buttonText);
    btn.addActionListener(this);
    p.add(btn);
    add("South", p);
    pack();

    Dimension dDim = getSize();
    if (parent != null) {
        Rectangle fRect = parent.getBounds();
        setLocation(fRect.x + ((fRect.width - dDim.width) / 2),
                    fRect.y + ((fRect.height - dDim.height) / 2));
    }
}
 
Example 2
Source File: DockHeader.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private void updateForDragOver(Point where) {
    int count    = getComponentCount();
    int insertAt = count;
    for (int i = 0; i < count; i++) {
        Component child = getComponent(i);
        if (child instanceof DockTab) {
            Rectangle bounds = child.getBounds();
            if (where.x < bounds.x + bounds.width / 2) {
                insertAt = i;
                break;
            }
            if (where.x < bounds.x + bounds.width) {
                insertAt = i + 1;
                break;
            }
        } else {
            insertAt = i;
            break;
        }
    }
    if (insertAt != mDragInsertIndex) {
        mDragInsertIndex = insertAt;
        repaint();
    }
}
 
Example 3
Source File: DefaultDesktopManager.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public void beginDraggingFrame(JComponent f) {
    setupDragMode(f);

    if (dragMode == FASTER_DRAG_MODE) {
      Component desktop = f.getParent();
      floatingItems = findFloatingItems(f);
      currentBounds = f.getBounds();
      if (desktop instanceof JComponent) {
          desktopBounds = ((JComponent)desktop).getVisibleRect();
      }
      else {
          desktopBounds = desktop.getBounds();
          desktopBounds.x = desktopBounds.y = 0;
      }
      desktopGraphics = JComponent.safelyGetGraphics(desktop);
      ((JInternalFrame)f).isDragging = true;
      didDrag = false;
    }

}
 
Example 4
Source File: TopComponentDraggable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
Rectangle getBounds() {
    Rectangle bounds = null;
    TopComponent modeTC = getTopComponent();
    if( null == modeTC ) {
        modeTC = mode.getSelectedTopComponent();
        if( null == modeTC ) {
            TopComponent[] tcs = mode.getTopComponents();
            if( null != tcs && tcs.length > 0 )
                modeTC = tcs[0];
        }
    }
    Component modeComp = ( Component ) SwingUtilities.getAncestorOfClass(ModeComponent.class, modeTC);
    if( modeComp != null ) {
        bounds = modeComp.getBounds();
    }
    return bounds;
}
 
Example 5
Source File: ProfilerTableHovers.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private Rectangle getRendererRect(int column, Component renderer) {
    int _column = table.convertColumnIndexToModel(column);
    
    // Do not show value hovers for standard renderers shortening values using '...'
    if (!(renderer instanceof ProfilerRenderer) &&
        !table.isScrollableColumn(_column))
            return null;
    
    // Do not show value hovers when explicitely disabled
    if (renderer instanceof JComponent)
        if (((JComponent)renderer).getClientProperty(ProfilerTable.PROP_NO_HOVER) != null)
            return null;
    
    Rectangle bounds = renderer.getBounds();
    bounds.x -= table.getColumnOffset(_column);
    
    return bounds;
}
 
Example 6
Source File: BasicScrollPaneUI.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void scrollHome(JScrollPane scrollpane) {
    JViewport vp = scrollpane.getViewport();
    Component view;
    if (vp != null && (view = vp.getView()) != null) {
        if (scrollpane.getComponentOrientation().isLeftToRight()) {
            vp.setViewPosition(new Point(0, 0));
        } else {
            Rectangle visRect = vp.getViewRect();
            Rectangle bounds = view.getBounds();
            vp.setViewPosition(new Point(bounds.width - visRect.width, 0));
        }
    }
}
 
Example 7
Source File: BasicScrollPaneUI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void scrollHome(JScrollPane scrollpane) {
    JViewport vp = scrollpane.getViewport();
    Component view;
    if (vp != null && (view = vp.getView()) != null) {
        if (scrollpane.getComponentOrientation().isLeftToRight()) {
            vp.setViewPosition(new Point(0, 0));
        } else {
            Rectangle visRect = vp.getViewRect();
            Rectangle bounds = view.getBounds();
            vp.setViewPosition(new Point(bounds.width - visRect.width, 0));
        }
    }
}
 
Example 8
Source File: InternalUtilities.java    From LGoodDatePicker with MIT License 5 votes vote down vote up
/**
 * isMouseWithinComponent, This returns true if the mouse is inside of the specified component,
 * otherwise returns false.
 */
static public boolean isMouseWithinComponent(Component component) {
    if (!component.isVisible()) {
        // component.getLocationOnScreen() will throw an
        // IllegalComponentStateException if the component
        // is currently not visible
        return false;
    }
    Point mousePos = MouseInfo.getPointerInfo().getLocation();
    Rectangle bounds = component.getBounds();
    bounds.setLocation(component.getLocationOnScreen());
    return bounds.contains(mousePos);
}
 
Example 9
Source File: BasicScrollPaneUI.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private void scrollEnd(JScrollPane scrollpane) {
    JViewport vp = scrollpane.getViewport();
    Component view;
    if (vp != null && (view = vp.getView()) != null) {
        Rectangle visRect = vp.getViewRect();
        Rectangle bounds = view.getBounds();
        if (scrollpane.getComponentOrientation().isLeftToRight()) {
            vp.setViewPosition(new Point(bounds.width - visRect.width,
                                     bounds.height - visRect.height));
        } else {
            vp.setViewPosition(new Point(0,
                                     bounds.height - visRect.height));
        }
    }
}
 
Example 10
Source File: RQueries.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void doLayout() {
    super.doLayout();
    Component c = getComponent(1);

    int h = c.getPreferredSize().height;
    Rectangle b = c.getBounds();

    b.y = (b.height - h) / 2 + 1;
    b.height = h;
    c.setBounds(b);
}
 
Example 11
Source File: BasicScrollPaneUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void scrollEnd(JScrollPane scrollpane) {
    JViewport vp = scrollpane.getViewport();
    Component view;
    if (vp != null && (view = vp.getView()) != null) {
        Rectangle visRect = vp.getViewRect();
        Rectangle bounds = view.getBounds();
        if (scrollpane.getComponentOrientation().isLeftToRight()) {
            vp.setViewPosition(new Point(bounds.width - visRect.width,
                                     bounds.height - visRect.height));
        } else {
            vp.setViewPosition(new Point(0,
                                     bounds.height - visRect.height));
        }
    }
}
 
Example 12
Source File: BasicScrollPaneUI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void scrollEnd(JScrollPane scrollpane) {
    JViewport vp = scrollpane.getViewport();
    Component view;
    if (vp != null && (view = vp.getView()) != null) {
        Rectangle visRect = vp.getViewRect();
        Rectangle bounds = view.getBounds();
        if (scrollpane.getComponentOrientation().isLeftToRight()) {
            vp.setViewPosition(new Point(bounds.width - visRect.width,
                                     bounds.height - visRect.height));
        } else {
            vp.setViewPosition(new Point(0,
                                     bounds.height - visRect.height));
        }
    }
}
 
Example 13
Source File: OQLQueries.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void doLayout() {
    super.doLayout();
    Component c = getComponent(1);

    int h = c.getPreferredSize().height;
    Rectangle b = c.getBounds();

    b.y = (b.height - h) / 2 + 1;
    b.height = h;
    c.setBounds(b);
}
 
Example 14
Source File: BasicScrollPaneUI.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private void scrollHome(JScrollPane scrollpane) {
    JViewport vp = scrollpane.getViewport();
    Component view;
    if (vp != null && (view = vp.getView()) != null) {
        if (scrollpane.getComponentOrientation().isLeftToRight()) {
            vp.setViewPosition(new Point(0, 0));
        } else {
            Rectangle visRect = vp.getViewRect();
            Rectangle bounds = view.getBounds();
            vp.setViewPosition(new Point(bounds.width - visRect.width, 0));
        }
    }
}
 
Example 15
Source File: BasicScrollPaneUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void scrollHome(JScrollPane scrollpane) {
    JViewport vp = scrollpane.getViewport();
    Component view;
    if (vp != null && (view = vp.getView()) != null) {
        if (scrollpane.getComponentOrientation().isLeftToRight()) {
            vp.setViewPosition(new Point(0, 0));
        } else {
            Rectangle visRect = vp.getViewRect();
            Rectangle bounds = view.getBounds();
            vp.setViewPosition(new Point(bounds.width - visRect.width, 0));
        }
    }
}
 
Example 16
Source File: DropPanel.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private void paintVerticalBackgrounds(Graphics gc, Rectangle localBounds) {
    for (Entry<Component, Color> entry : mVerticalBackgrounds.entrySet()) {
        Component panel  = entry.getKey();
        Rectangle bounds = panel.getBounds();
        Container parent = panel.getParent();
        if (parent != null) {
            if (parent != this) {
                UIUtilities.convertRectangle(bounds, parent, this);
            }
            gc.setColor(entry.getValue());
            gc.fillRect(bounds.x, localBounds.y, bounds.width, localBounds.height);
        }
    }
}
 
Example 17
Source File: BasicScrollPaneUI.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private void scrollHome(JScrollPane scrollpane) {
    JViewport vp = scrollpane.getViewport();
    Component view;
    if (vp != null && (view = vp.getView()) != null) {
        if (scrollpane.getComponentOrientation().isLeftToRight()) {
            vp.setViewPosition(new Point(0, 0));
        } else {
            Rectangle visRect = vp.getViewRect();
            Rectangle bounds = view.getBounds();
            vp.setViewPosition(new Point(bounds.width - visRect.width, 0));
        }
    }
}
 
Example 18
Source File: BasicScrollPaneUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void scrollEnd(JScrollPane scrollpane) {
    JViewport vp = scrollpane.getViewport();
    Component view;
    if (vp != null && (view = vp.getView()) != null) {
        Rectangle visRect = vp.getViewRect();
        Rectangle bounds = view.getBounds();
        if (scrollpane.getComponentOrientation().isLeftToRight()) {
            vp.setViewPosition(new Point(bounds.width - visRect.width,
                                     bounds.height - visRect.height));
        } else {
            vp.setViewPosition(new Point(0,
                                     bounds.height - visRect.height));
        }
    }
}
 
Example 19
Source File: SummaryCellRenderer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void computeBounds (Component component) {
    bounds = component.getBounds();
}
 
Example 20
Source File: ImageHelper.java    From magarena with GNU General Public License v3.0 4 votes vote down vote up
private static BufferedImage getScreenshotImage(final Component container) {
    final Rectangle rec = container.getBounds();
    final BufferedImage capture = getCompatibleBufferedImage(rec.width, rec.height);
    container.paint(capture.getGraphics());
    return capture;
}