当前位置: 首页>>代码示例>>Java>>正文


Java Component.getSize方法代码示例

本文整理汇总了Java中java.awt.Component.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java Component.getSize方法的具体用法?Java Component.getSize怎么用?Java Component.getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Component的用法示例。


在下文中一共展示了Component.getSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: focusGained

import java.awt.Component; //导入方法依赖的package包/类
@Override
public void focusGained(FocusEvent e) {
    if (e.isTemporary()) {
        return;
    }
    Component cmp = e.getComponent();
    if(cmp instanceof JComponent) {
        JViewport vp = getViewport(container);
        if(vp == null) {
            return;
        }
        Rectangle vr = vp.getViewRect();
        Point p = SwingUtilities.convertPoint(cmp.getParent(), cmp.getLocation(), container);
        final Rectangle r = new Rectangle(p, cmp.getSize());
        if(vr.intersects(r)) {
            return; 
        }
        container.scrollRectToVisible(r);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:UIUtils.java

示例2: paint

import java.awt.Component; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
    Rectangle r = getBounds();
    g.setColor(Color.lightGray);
    g.draw3DRect(0, 0, r.width, r.height, false);

    int n = getComponentCount();
    for (int i = 0; i < n; i++) {
        Component comp = getComponent(i);
        if (comp instanceof Checkbox) {
            Point loc = comp.getLocation();
            Dimension d = comp.getSize();
            g.setColor(comp.getForeground());
            g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:DrawTest.java

示例3: ensureMaximumSize

import java.awt.Component; //导入方法依赖的package包/类
public static void ensureMaximumSize(Component c, int width, int height)
{
	Dimension size = c.getSize();

	if( size.width > width )
	{
		size.width = width;
	}

	if( size.height > height )
	{
		size.height = height;
	}

	c.setSize(size);
}
 
开发者ID:equella,项目名称:Equella,代码行数:17,代码来源:ComponentHelper.java

示例4: paintIcon

import java.awt.Component; //导入方法依赖的package包/类
@Override
public void paintIcon(Component destination, Graphics g) {
	Dimension dim = destination.getSize();
	g.setColor(Color.GRAY);
	int x = 0;
	int y = 0;
	int w = dim.width;
	int h = dim.height;
	if (h >= w) { // separator is a vertical line in horizontal toolbar
		h -= 8;
		y = 2;
		x = (w - 2) / 2;
		w = 2;
	} else { // separator is a horizontal line in vertical toolbar
		w -= 8;
		x = 2;
		y = (h - 2) / 2;
		h = 2;
	}
	g.fillRect(x, y, w, h);
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:22,代码来源:ToolbarSeparator.java

示例5: paint

import java.awt.Component; //导入方法依赖的package包/类
/** Overridden to draw "no properties" if necessary */
public void paint(Graphics g, JComponent c) {
    Component view = ((JViewport) c).getView();

    if (view != null) {
        lastKnownSize = view.getSize();
    }

    if (stringWidth == -1) {
        calcStringSizes(c.getFont(), g);
    }

    //Update will have set paintNoProps to the correct value
    if (shouldPaintEmptyMessage()) {
        //We need to paint centered "<No Properties>" text
        g.setFont(c.getFont());
        g.setColor(c.getForeground());

        Rectangle r = getEmptyMessageBounds();

        //See if we really need to do any painting
        if (g.hitClip(r.x, r.y, r.width, r.height)) {
            //Paint the string
            g.drawString(emptyString, r.x, r.y + ascent);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:MarginViewportUI.java

示例6: paintBorder

import java.awt.Component; //导入方法依赖的package包/类
public void paintBorder(Component c, Graphics g, int x, int y,
                        int width, int height) {
    if (!(c instanceof BasicSplitPaneDivider)) {
        return;
    }
    Component          child;
    Rectangle          cBounds;
    JSplitPane         splitPane = ((BasicSplitPaneDivider)c).
                                 getBasicSplitPaneUI().getSplitPane();
    Dimension          size = c.getSize();

    child = splitPane.getLeftComponent();
    // This is needed for the space between the divider and end of
    // splitpane.
    g.setColor(c.getBackground());
    g.drawRect(x, y, width - 1, height - 1);
    if(splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
        if(child != null) {
            g.setColor(highlight);
            g.drawLine(0, 0, 0, size.height);
        }
        child = splitPane.getRightComponent();
        if(child != null) {
            g.setColor(shadow);
            g.drawLine(size.width - 1, 0, size.width - 1, size.height);
        }
    } else {
        if(child != null) {
            g.setColor(highlight);
            g.drawLine(0, 0, size.width, 0);
        }
        child = splitPane.getRightComponent();
        if(child != null) {
            g.setColor(shadow);
            g.drawLine(0, size.height - 1, size.width,
                       size.height - 1);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:40,代码来源:BasicBorders.java

示例7: focusGained

import java.awt.Component; //导入方法依赖的package包/类
@Override
public void focusGained(FocusEvent e) {
    Component c = e.getComponent();
    if(c instanceof JComponent) {
        Point p = SwingUtilities.convertPoint(c.getParent(), c.getLocation(), repoPanel);
        final Rectangle r = new Rectangle(p, c.getSize());
        UIUtils.runInAWT(new Runnable() {
            @Override
            public void run() {
                repoPanel.scrollRectToVisible(r);
            }
        });
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:QueryTopComponent.java

示例8: paintIcon

import java.awt.Component; //导入方法依赖的package包/类
public void paintIcon(Component c, Graphics g, int x, int y) {
  Dimension size = c.getSize();
  Graphics g2 = g.create(size.width / 2 - 5, size.height / 2 - 5, 10, 10);
  g2.setColor(Color.GRAY);
  g2.drawPolygon(xPoints, yPoints, 3);
  if (c.isEnabled()) {
    g2.setColor(Color.BLACK);
    g2.fillPolygon(xPoints, yPoints, 3);
  }
  g2.dispose();
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:12,代码来源:MenuScroller.java

示例9: moveMouseTo

import java.awt.Component; //导入方法依赖的package包/类
/**
 * Move mouse cursor to the center of the Component.
 * @param c Component the mouse is placed over
 */
public void moveMouseTo(Component c) {
    Point p = c.getLocationOnScreen();
    Dimension size = c.getSize();
    p.x += size.width / 2;
    p.y += size.height / 2;
    mouseMove(p.x, p.y);
    delay();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:JRobot.java

示例10: placethem

import java.awt.Component; //导入方法依赖的package包/类
private void placethem(Container container, int x, int y, int l, int first, int last)
{
	// Set the x position:
	Insets insets = container.getInsets();
	int width = (int) (container.getSize().getWidth());
	int right = width - insets.right;
	int middle = insets.left + ((width - insets.left - insets.right) / 2);

	int k1 = getAlignment();
	if( k1 == 1 )
	{
		y += l / 2;
	}

	if( k1 == 2 )
	{
		y += l;
	}

	for( int i = first; i < last; i++ )
	{
		Component component = container.getComponent(i);
		Dimension size = component.getSize();
		if( component.isVisible() )
		{
			if( hAlign == CENTER )
			{
				x = middle - size.width / 2;
			}
			else if( hAlign == RIGHT )
			{
				x = right - size.width;
			}
			component.setLocation(x, y);
			y += vgap + size.height;
		}
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:39,代码来源:VerticalFlowLayout.java

示例11: clickOnTitle

import java.awt.Component; //导入方法依赖的package包/类
void clickOnTitle(Component c) {
    Point p = c.getLocationOnScreen();
    Dimension d = c.getSize();
    robot.mouseMove(p.x + (int)(d.getWidth() / 2),
                    p.y + ((Frame)c).getInsets().top / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.delay(20);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:DisposeDialogNotActivateOwnerTest.java

示例12: showDialog

import java.awt.Component; //导入方法依赖的package包/类
public static int showDialog(Component comp, String text) {
    ReplaceOptionsDialog dlg = new ReplaceOptionsDialog(text);
    Dimension dlgSize = new Dimension(300, 150);
    dlg.setSize(300, 150);
    Dimension frmSize = comp.getSize();
    Point loc = comp.getLocationOnScreen();
    dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
    dlg.setModal(true);
    dlg.setVisible(true);
    return dlg.option;
}
 
开发者ID:ser316asu,项目名称:SER316-Ingolstadt,代码行数:12,代码来源:ReplaceOptionsDialog.java

示例13: pointOnComp

import java.awt.Component; //导入方法依赖的package包/类
/**
 * Moves mouse pointer in the center of given {@code comp} component
 * using {@code robot} parameter.
 */
public static void pointOnComp(final Component comp, final Robot robot) {
    Rectangle bounds = new Rectangle(comp.getLocationOnScreen(), comp.getSize());
    robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:Util.java

示例14: scroll

import java.awt.Component; //导入方法依赖的package包/类
private void scroll(JScrollPane scrollpane, int orientation,
                    int direction, boolean block) {
    JViewport vp = scrollpane.getViewport();
    Component view;
    if (vp != null && (view = vp.getView()) != null) {
        Rectangle visRect = vp.getViewRect();
        Dimension vSize = view.getSize();
        int amount;

        if (view instanceof Scrollable) {
            if (block) {
                amount = ((Scrollable)view).getScrollableBlockIncrement
                         (visRect, orientation, direction);
            }
            else {
                amount = ((Scrollable)view).getScrollableUnitIncrement
                         (visRect, orientation, direction);
            }
        }
        else {
            if (block) {
                if (orientation == SwingConstants.VERTICAL) {
                    amount = visRect.height;
                }
                else {
                    amount = visRect.width;
                }
            }
            else {
                amount = 10;
            }
        }
        if (orientation == SwingConstants.VERTICAL) {
            visRect.y += (amount * direction);
            if ((visRect.y + visRect.height) > vSize.height) {
                visRect.y = Math.max(0, vSize.height - visRect.height);
            }
            else if (visRect.y < 0) {
                visRect.y = 0;
            }
        }
        else {
            if (scrollpane.getComponentOrientation().isLeftToRight()) {
                visRect.x += (amount * direction);
                if ((visRect.x + visRect.width) > vSize.width) {
                    visRect.x = Math.max(0, vSize.width - visRect.width);
                } else if (visRect.x < 0) {
                    visRect.x = 0;
                }
            } else {
                visRect.x -= (amount * direction);
                if (visRect.width > vSize.width) {
                    visRect.x = vSize.width - visRect.width;
                } else {
                    visRect.x = Math.max(0, Math.min(vSize.width - visRect.width, visRect.x));
                }
            }
        }
        vp.setViewPosition(visRect.getLocation());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:62,代码来源:BasicScrollPaneUI.java

示例15: getPoint

import java.awt.Component; //导入方法依赖的package包/类
private static Point getPoint(Component component, double scale) {
    Point point = component.getLocationOnScreen();
    Dimension bounds = component.getSize();
    point.translate((int) (bounds.width * scale), (int) (bounds.height * scale));
    return point;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:DNDTextToScaledArea.java


注:本文中的java.awt.Component.getSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。