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

The following examples show how to use java.awt.Component#getWidth() . 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
public Polygon getInteriorPolygon(Component c) {
    NimbusEditorTabCellRenderer ren = (NimbusEditorTabCellRenderer) c;

    Insets ins = getBorderInsets(c);
    Polygon p = new Polygon();
    int x = -3;
    int y = 0;

    int width = c.getWidth() + 3;
    int height = c.getHeight() - 4;

    //Modified to return rectangle
    p.addPoint(x, y);
    p.addPoint(x + width, y);
    p.addPoint(x + width, y + height);
    p.addPoint(x, y + height);
    return p;
}
 
Example 2
Source Project: pdfxtk   File: GraphPanel.java    License: Apache License 2.0 6 votes vote down vote up
public GraphPort findPortAt(GraphNode node, int mx, int my) {
   GraphPort[] ports = node.getPorts();

   Component cmp = (Component)node.get(COMPONENT);
   
   int    mind = Integer.MAX_VALUE;
   int    min  = 0;
   int    cw   = cmp.getWidth();
   int    ch   = cmp.getHeight();
   int    cx   = cmp.getX();
   int    cy   = cmp.getY();
   for(int i = 0; i < ports.length; i++) {
     GraphNodePort port = (GraphNodePort)ports[i].get(GRAPH_NODE_PORT);
     if(port == null) return null;
     int x = mx - (int)(port.x * cw + cx);
     int y = my - (int)(port.y * ch + cy);
     int d = x * x + y * y;
     if(d < mind) {
min  = i;
mind = d;
     }
   }
   
   return ports[min];
 }
 
Example 3
Source Project: osp   File: SnapshotTool.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructor ComponentImage
 * @param comp
 */
public ComponentImage(Component comp) {
  c = comp;
  if(comp instanceof JFrame) {
    comp = ((JFrame) comp).getContentPane();
  } else if(comp instanceof JDialog) {
    comp = ((JDialog) comp).getContentPane();
  }
  image = new BufferedImage(comp.getWidth(), comp.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
  if(comp instanceof Renderable) {
    image = ((Renderable) comp).render(image);
  } else {
    java.awt.Graphics g = image.getGraphics();
    comp.paint(g);
    g.dispose();
  }
}
 
Example 4
Source Project: netbeans   File: ProfilerTable.java    License: Apache License 2.0 6 votes vote down vote up
Component getRenderer(TableCellRenderer renderer, int row, int column, boolean sized) {
        isCustomRendering = true;
        try {
            Component comp = prepareRenderer(renderer, row, column);
//            comp.setSize(comp.getPreferredSize().width, getRowHeight());
            if (sized) {
                comp.setSize(comp.getPreferredSize().width, getRowHeight());
                if (!isLeadingAlign(comp)) {
                    TableColumnModel m = getColumnModel();
                    int x = -comp.getWidth();
                    int c = m.getColumn(column).getWidth();
                    int _column = convertColumnIndexToModel(column);
                    if (isScrollableColumn(_column)) {
                        x += Math.max(c, getColumnPreferredWidth(_column));
                    } else {
                        x += c;
                    }
                    comp.move(x - m.getColumnMargin(), 0);
                }
            }
            
            return comp;
        } finally {
            isCustomRendering = false;
        }
    }
 
Example 5
@Override
public Polygon getInteriorPolygon(Component c) {
    int x = 0;
    int y = 0;
    int width = c.getWidth();
    int height = c.getHeight();

    //just a plain rectangle
    Polygon p = new Polygon();
    p.addPoint(x, y);
    p.addPoint(x + width, y);
    p.addPoint(x + width, y + height);
    p.addPoint(x, y + height);
    return p;
}
 
Example 6
Source Project: netbeans   File: ToolbarContainer.java    License: Apache License 2.0 5 votes vote down vote up
private void paintDropGesture( Graphics g ) {
    Component c = toolbar.getComponentAtIndex( dropIndex );
    if( null == c )
        return;

    Point location = c.getLocation();
    int cursorLocation = location.x;
    if( !dropBefore ) {
        cursorLocation += c.getWidth();
        if( dropIndex == toolbar.getComponentCount()-1 )
            cursorLocation -= 3;
    }
    drawDropLine( g, cursorLocation );
}
 
Example 7
Source Project: Luyten   File: WindowPosition.java    License: Apache License 2.0 5 votes vote down vote up
private void readPositionFromComponent(Component component) {
	isFullScreen = false;
	windowWidth = component.getWidth();
	windowHeight = component.getHeight();
	windowX = component.getX();
	windowY = component.getY();
}
 
Example 8
public static void drawMenuItemFading(Component c, Graphics g) {
	int w = c.getWidth();
	int h = c.getHeight();
	if (h < 0 || w < 0) {
		return;
	}

	g.setColor(Colors.MENU_ITEM_BACKGROUND);
	g.fillRect(0, 0, w, h);
}
 
Example 9
/**
 * Creates a VolatileImage that essentially wraps the target Component's
 * backbuffer (the provided backbuffer handle is essentially ignored).
 */
@Override
public VolatileImage createBackBufferImage(Component target,
                                           long backBuffer)
{
    return new SunVolatileImage(target,
                                target.getWidth(), target.getHeight(),
                                Boolean.TRUE);
}
 
Example 10
Source Project: workcraft   File: SmartFlowLayout.java    License: MIT License 5 votes vote down vote up
private void moveComponents(Container target, int x, int y, int remainingWidth, int height,
        int rowStart, int rowEnd, boolean ltr) {
    switch (newAlign) {
    case LEFT:
        x += ltr ? 0 : remainingWidth;
        break;
    case CENTER:
        x += remainingWidth / 2;
        break;
    case RIGHT:
        x += ltr ? remainingWidth : 0;
        break;
    case LEADING:
        break;
    case TRAILING:
        x += remainingWidth;
        break;
    }
    for (int i = rowStart; i < rowEnd; i++) {
        Component m = target.getComponent(i);
        if (m.isVisible()) {
            int cy = y + (height - m.getHeight()) / 2;
            if (ltr) {
                m.setLocation(x, cy);
            } else {
                m.setLocation(target.getWidth() - x - m.getWidth(), cy);
            }
            x += m.getWidth() + hgap;
        }
    }
}
 
Example 11
Source Project: rest-client   File: UIUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
* 
* @Title: setLocation 
* @Description: set component's location
* @param @param c 
* @return void
* @throws
 */
public static void setLocation(Component c)
{
    int winWidth = c.getWidth();
    int winHeight = c.getHeight();

    Toolkit kit = Toolkit.getDefaultToolkit();
    Dimension screenSize = kit.getScreenSize();

    int screenWidth = screenSize.width;
    int screenHeight = screenSize.height;

    c.setLocation(screenWidth / 2 - winWidth / 2, screenHeight / 2 - winHeight / 2);
}
 
Example 12
/**
 * Creates a VolatileImage that essentially wraps the target Component's
 * backbuffer, using the provided backbuffer handle.
 */
public VolatileImage createBackBufferImage(Component target,
                                           long backBuffer)
{
    return new SunVolatileImage(target,
                                target.getWidth(), target.getHeight(),
                                Long.valueOf(backBuffer));
}
 
Example 13
private static void doCapture(Component test) {
    try {
        Thread.sleep(2000);
    } catch (InterruptedException ex) {}
    // Grab the screen region
    try {
        Robot robot = new Robot();
        Point pt1 = test.getLocationOnScreen();
        Rectangle rect =
            new Rectangle(pt1.x, pt1.y, test.getWidth(), test.getHeight());
        capture = robot.createScreenCapture(rect);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 14
Source Project: lsdpatch   File: StretchIcon.java    License: MIT License 5 votes vote down vote up
/**
 * Paints the icon. The image is reduced or magnified to fit the component to which it is painted.
 * <P>
 * If the proportion has not been specified, or has been specified as <code>true</code>, the aspect ratio of the image will be preserved
 * by padding and centering the image horizontally or vertically. Otherwise the image may be distorted to fill the component it is
 * painted to.
 * <P>
 * If this icon has no image observer,this method uses the <code>c</code> component as the observer.
 *
 * @param c the component to which the Icon is painted. This is used as the observer if this icon has no image observer
 * @param g the graphics context
 * @param x not used.
 * @param y not used.
 *
 * @see ImageIcon#paintIcon(java.awt.Component, java.awt.Graphics, int, int)
 */
@Override
public synchronized void paintIcon(Component c, Graphics g, int x, int y)
{
    Image image = getImage();
    if (image == null)
    {
        return;
    }
    Insets insets = ((Container) c).getInsets();
    x = insets.left;
    y = insets.top;

    int w = c.getWidth() - x - insets.right;
    int h = c.getHeight() - y - insets.bottom;

    if (proportionate)
    {
        int iw = image.getWidth(c);
        int ih = image.getHeight(c);

        if ((iw * h) < (ih * w))
        {
            iw = (h * iw) / ih;
            x += (w - iw) / 2;
            w = iw;
        }
        else
        {
            ih = (w * ih) / iw;
            y += (h - ih) / 2;
            h = ih;
        }
    }
    ImageObserver io = getImageObserver();
    g.drawImage(image, x, y, w, h, io == null ? c : io);
}
 
Example 15
/**
 * Creates a VolatileImage that essentially wraps the target Component's
 * backbuffer, using the provided backbuffer handle.
 */
public VolatileImage createBackBufferImage(Component target,
                                           long backBuffer)
{
    return new SunVolatileImage(target,
                                target.getWidth(), target.getHeight(),
                                Long.valueOf(backBuffer));
}
 
Example 16
public float getWidth (Component widget) {
	return widget.getWidth();
}
 
Example 17
protected Rectangle getControlButtonsRectangle(Container parent) {
    Component c = getControlButtons();
    return new Rectangle(parent.getWidth() - c.getWidth() - ICON_X_PAD,
            (parent.getHeight() - c.getHeight()) / 2, c.getWidth(), c.getHeight());
}
 
Example 18
/**
 * This method is called from WComponentPeer when a surface data is replaced
 * REMIND: while the default pipeline doesn't support flipping, it may
 * happen that the accelerated device may have this graphics config
 * (like if the device restoration failed when one device exits fs mode
 * while others remain).
 */
public VolatileImage createBackBuffer(WComponentPeer peer) {
    Component target = (Component)peer.getTarget();
    return new SunVolatileImage(target,
                                target.getWidth(), target.getHeight(),
                                Boolean.TRUE);
}
 
Example 19
/**
 * This method is called from WComponentPeer when a surface data is replaced
 * REMIND: while the default pipeline doesn't support flipping, it may
 * happen that the accelerated device may have this graphics config
 * (like if the device restoration failed when one device exits fs mode
 * while others remain).
 */
public VolatileImage createBackBuffer(WComponentPeer peer) {
    Component target = (Component)peer.getTarget();
    return new SunVolatileImage(target,
                                target.getWidth(), target.getHeight(),
                                Boolean.TRUE);
}
 
Example 20
/**
 * This method is called from WComponentPeer when a surface data is replaced
 * REMIND: while the default pipeline doesn't support flipping, it may
 * happen that the accelerated device may have this graphics config
 * (like if the device restoration failed when one device exits fs mode
 * while others remain).
 */
public VolatileImage createBackBuffer(WComponentPeer peer) {
    Component target = (Component)peer.getTarget();
    return new SunVolatileImage(target,
                                target.getWidth(), target.getHeight(),
                                Boolean.TRUE);
}