Java Code Examples for javax.swing.JComponent#setLocation()

The following examples show how to use javax.swing.JComponent#setLocation() . These examples are extracted from open source projects. 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
/**
 * Do the adjustment on the specified popupComponent immediately before
 * it is displayed.
 */
private void fixPopupLocation(JComponent popupComponent) {
    // we only need to fix Apple's aqua look and feel
    if(popupComponent.getClass().getName().indexOf("apple.laf") != 0) {
        return;
    }
    
    // put the popup right under the combo box so it looks like a
    // normal Aqua combo box
    Point comboLocationOnScreen = comboBox.getLocationOnScreen();
    int comboHeight = comboBox.getHeight();
    int popupY = comboLocationOnScreen.y + comboHeight;
    
    // ...unless the popup overflows the screen, in which case we put it
    // above the combobox
    Rectangle screenBounds = new ScreenGeometry(comboBox).getScreenBounds();
    int popupHeight = popupComponent.getPreferredSize().height;
    if(comboLocationOnScreen.y + comboHeight + popupHeight > screenBounds.x + screenBounds.height) {
        popupY = comboLocationOnScreen.y - popupHeight;
    }
    
    popupComponent.setLocation(comboLocationOnScreen.x, popupY);
}
 
Example 2
private void installInLayeredPane(JComponent component) {
    JLayeredPane layeredPane = getRootPane().getLayeredPane();
    layeredPane.add(component, JLayeredPane.PALETTE_LAYER, 20);
    Dimension size = component.getPreferredSize();
    component.setSize(size);
    component.setLocation((getWidth() - size.width) / 2,
            (getHeight() - size.height) / 2);
    component.revalidate();
    component.setVisible(true);
}
 
Example 3
Source Project: seaglass   File: SeaGlassDesktopPaneUI.java    License: Apache License 2.0 4 votes vote down vote up
public void setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
    super.setBoundsForFrame(f, newX, newY, newWidth, newHeight);
    if (taskBar != null && newY >= taskBar.getY()) {
        f.setLocation(f.getX(), taskBar.getY() - f.getInsets().top);
    }
}