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

The following examples show how to use java.awt.Component#getWidth() . 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: NimbusEditorTabCellRenderer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 File: ProfilerTable.java    From netbeans with 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 3
Source File: GraphPanel.java    From pdfxtk with 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 4
Source File: SnapshotTool.java    From osp with 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 5
Source File: SmartFlowLayout.java    From workcraft with 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 6
Source File: X11GraphicsConfig.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 7
Source File: StretchIcon.java    From lsdpatch with 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 8
Source File: DrawImageBilinear.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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 9
Source File: X11GraphicsConfig.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 10
Source File: UIUtil.java    From rest-client with 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 11
Source File: FlatEditorTabCellRenderer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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 12
Source File: GLXGraphicsConfig.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 13
Source File: RapidLookTools.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
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 14
Source File: WindowPosition.java    From Luyten with 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 15
Source File: ToolbarContainer.java    From netbeans with 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 16
Source File: FlatEditorTabDisplayerUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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 17
Source File: SwingToolkit.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
public float getWidth (Component widget) {
	return widget.getWidth();
}
 
Example 18
Source File: Win32GraphicsConfig.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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
Source File: Win32GraphicsConfig.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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
Source File: Win32GraphicsConfig.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}