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


Java Component.getWidth方法代码示例

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


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

示例1: isButtonOnScreen

import java.awt.Component; //导入方法依赖的package包/类
/**
 * method to get to know whether the AbstractButton with the given key is on Screen
 *
 * @param dockableKey
 *            i18nKey of the wanted AbstractButton
 * @return returns 0 if the AbstractButton is on the Screen, 1 if the AbstractButton is on
 *         Screen but the user can not see it with the current settings of the perspective and
 *         -1 if the AbstractButton is not on the Screen.
 */
public static int isButtonOnScreen(final String buttonKey) {
	// find the Button and return -1 if we can not find it
	Component onScreen;
	try {
		onScreen = BubbleWindow.findButton(buttonKey, RapidMinerGUI.getMainFrame());
	} catch (NullPointerException e) {
		return OBJECT_NOT_ON_SCREEN;
	}
	if (onScreen == null) {
		return OBJECT_NOT_ON_SCREEN;
	}
	// detect whether the Button is viewable
	int xposition = onScreen.getLocationOnScreen().x;
	int yposition = onScreen.getLocationOnScreen().y;
	int otherXposition = xposition + onScreen.getWidth();
	int otherYposition = yposition + onScreen.getHeight();
	Window frame = RapidMinerGUI.getMainFrame();
	if (otherXposition <= frame.getWidth() && otherYposition <= frame.getHeight() && xposition > 0 && yposition > 0) {
		return OBJECT_SHOWING_ON_SCREEN;
	} else {
		return OBJECT_NOT_SHOWING;
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:33,代码来源:BubbleWindow.java

示例2: getPreferredSize

import java.awt.Component; //导入方法依赖的package包/类
@Override
public Dimension getPreferredSize() {
    Dimension d = super.getPreferredSize();
    if( null != getParent() && null != getParent().getParent() ) {
        Component scroll = getParent().getParent();
        if( scroll.getWidth() > 0 ) {
            if( d.width > scroll.getWidth() ) {
                d.width = Math.max(scroll.getWidth(), START_PAGE_MIN_WIDTH+(int)(((FONT_SIZE-11)/11.0)*START_PAGE_MIN_WIDTH));
            } else if( d.width < scroll.getWidth() ) {
                d.width = scroll.getWidth();
            }
        }
    }
    d.width = Math.min( d.width, 1000 );
    return d;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:TabbedPane.java

示例3: mouseClickOnComp

import java.awt.Component; //导入方法依赖的package包/类
static void mouseClickOnComp(Robot r, Component comp) {
    Point loc = comp.getLocationOnScreen();
    loc.x += comp.getWidth() / 2;
    loc.y += comp.getHeight() / 2;
    r.mouseMove(loc.x, loc.y);
    r.delay(10);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.delay(10);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:InputVerifierTest2.java

示例4: createContentImage

import java.awt.Component; //导入方法依赖的package包/类
private BufferedImage createContentImage( Component c, Dimension contentSize ) {
    GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().getDefaultConfiguration();

    BufferedImage res = config.createCompatibleImage(contentSize.width, contentSize.height);
    Graphics2D g = res.createGraphics();
    //some components may be non-opaque so just black rectangle would be painted then
    g.setColor( Color.white );
    g.fillRect(0, 0, contentSize.width, contentSize.height);
    if( WinSysPrefs.HANDLER.getBoolean(WinSysPrefs.DND_SMALLWINDOWS, true) && c.getWidth() > 0 && c.getHeight() > 0 ) {
        double xScale = contentSize.getWidth() / c.getWidth();
        double yScale = contentSize.getHeight() / c.getHeight();
        g.setTransform(AffineTransform.getScaleInstance(xScale, yScale) );
    }
    c.paint(g);
    return res;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:DragWindow.java

示例5: calculatePosition

import java.awt.Component; //导入方法依赖的package包/类
private Point calculatePosition(Component source) {
	int xSource = source.getLocationOnScreen().x;
	int ySource = source.getLocationOnScreen().y;

	// get size of popup
	Dimension popupSize = ((Component) popupComponent).getSize();
	if (popupSize.width == 0) {
		popupSize = ((Component) popupComponent).getPreferredSize();
	}

	int xPopup = 0;
	int yPopup = 0;

	// get max x and y window positions
	Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
	int maxX = focusedWindow.getLocationOnScreen().x + focusedWindow.getWidth();
	int maxY = focusedWindow.getLocationOnScreen().y + focusedWindow.getHeight();

	switch (position) {
		case VERTICAL:

			// place popup at sources' x position
			xPopup = xSource;

			// check if popup is outside active window
			if (xPopup + popupSize.width > maxX) {

				// move popup x position to the left
				// to fit inside the active window
				xPopup = maxX - popupSize.width - BORDER_OFFSET;
			}

			// place popup always below source (to avoid overlapping)
			yPopup = ySource + source.getHeight();

			// if the popup now would be moved outside of RM Studio to the left it would look
			// silly, so in that case just show it at its intended position and let it be cut
			// off on the right side as we cannot do anything about it
			if (xPopup < focusedWindow.getLocationOnScreen().x
					|| (xPopup - focusedWindow.getLocationOnScreen().x) + popupSize.width > focusedWindow.getWidth()) {
				xPopup = xSource;
			}

			break;
		case HORIZONTAL:

			// place popup always to the right side of the source (to avoid overlapping)
			xPopup = xSource + source.getWidth();

			yPopup = ySource;

			// check if popup is outside active window
			if (yPopup + popupSize.height > maxY) {

				// move popup upwards to fit into active window
				yPopup = maxY - popupSize.height - BORDER_OFFSET;
			}

			// if the popup now would be moved outside of RM Studio at the top it would look
			// silly, so in that case just show it at its intended position and let it be cut
			// off on the bottom side as we cannot do anything about it
			if (yPopup < focusedWindow.getLocationOnScreen().y
					|| (yPopup - focusedWindow.getLocationOnScreen().y) + popupSize.height > focusedWindow.getHeight()) {
				yPopup = ySource;
			}

			break;
	}

	return new Point(xPopup, yPopup);

}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:73,代码来源:PopupAction.java

示例6: printContainer

import java.awt.Component; //导入方法依赖的package包/类
/**
 * Salva uma imagem .png com o print do container
 *
 * @param component objeto container
 * @param file local onde a imagem será salva
 */
public static void printContainer(Component component, File file) {
    int width = component.getWidth();
    int height = component.getHeight();
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics graphics = image.getGraphics();
    component.paintAll(graphics);
    graphics.dispose();
    try {
        ImageIO.write(image, "PNG", file);
    } catch (IOException ex) {
    }
}
 
开发者ID:limagiran,项目名称:hearthstone,代码行数:19,代码来源:Img.java

示例7: createBackBufferImage

import java.awt.Component; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:GLXGraphicsConfig.java

示例8: eventDispatched

import java.awt.Component; //导入方法依赖的package包/类
public void eventDispatched(AWTEvent event) {
    if (event instanceof MouseEvent) {
        MouseEvent me = (MouseEvent) event;
        Component mecmp = me.getComponent();

        if (!SwingUtilities.isDescendingFrom(mecmp, (Component) rootPaneContainer)) {
            return;
        }
        if ((me.getID() == MouseEvent.MOUSE_EXITED) && (mecmp == rootPaneContainer)) {
            highcmp = null;
            point = null;
        } else {
            MouseEvent converted = SwingUtilities.convertMouseEvent(mecmp, me, this);
            point = converted.getPoint();
            Component parent = mecmp;
            Rectangle rect = new Rectangle();
            rect.width = mecmp.getWidth();
            rect.height = mecmp.getHeight();
            Rectangle parentBounds = new Rectangle();
            while ((parent != null) && (parent != this.getRootPane()) && (parent != rootPaneContainer)) {
                parent.getBounds(parentBounds);
                rect.x += parentBounds.x;
                rect.y += parentBounds.y;
                parent = parent.getParent();
            }
            highcmp = rect;
        }
        repaint();
    }
}
 
开发者ID:igr,项目名称:swingspy,代码行数:31,代码来源:SwingSpyGlassPane.java

示例9: readPositionFromComponent

import java.awt.Component; //导入方法依赖的package包/类
private void readPositionFromComponent(Component component) {
	isFullScreen = false;
	windowWidth = component.getWidth();
	windowHeight = component.getHeight();
	windowX = component.getX();
	windowY = component.getY();
}
 
开发者ID:KevinPriv,项目名称:Luyten4Forge,代码行数:8,代码来源:WindowPosition.java

示例10: showWindow

import java.awt.Component; //导入方法依赖的package包/类
private void showWindow(JTable table, int row) {

		/* determine correct location */
		//TODO: throw away half of this rubbish
		Point offset = new Point();
		Point tablebase = table.getLocationOnScreen();
		Point framebase = owner.getLocationOnScreen();

		Rectangle cellRect = table.getCellRect(row, 0, true);
		int middle = table.getHeight() / 2;

		int deltax, deltay, width;

		deltay = tablebase.y - framebase.y;

		Component c = table.getParent();
		if (c instanceof JViewport) { //we are in a JScrollPane
			c = c.getParent();
			deltax = c.getLocationOnScreen().x - framebase.x;
			width = c.getWidth();
		} else {
			deltax = tablebase.x - framebase.x;
			width = table.getWidth();
		}

		offset.x = cellRect.x + deltax;

		if (cellRect.y > middle) {
			offset.y = cellRect.y - ldWindow.getHeight() + deltay;
		} else {
			offset.y = cellRect.y + cellRect.height + deltay;
		}
		//ldWindow.setBase(framebase);
		//ldWindow.setOffset(offset);

		ldWindow.centerWindow(width, ldWindow.getHeight());
		ldWindow.show();
	}
 
开发者ID:max6cn,项目名称:jmt,代码行数:39,代码来源:LDEditor.java

示例11: createBackBufferImage

import java.awt.Component; //导入方法依赖的package包/类
/**
 * 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));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:X11GraphicsConfig.java

示例12: drawMenuSeparator

import java.awt.Component; //导入方法依赖的package包/类
public static boolean drawMenuSeparator(Component c, Graphics g) {
	int w = c.getWidth();
	int h = c.getHeight();
	if (h < 0 || w < 0) {
		return true;
	}
	MenuSeparatorPainter.SINGLETON.paint(c, g, c.getX(), c.getY(), w, h);
	return true;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:10,代码来源:CachedPainter.java

示例13: showPopup

import java.awt.Component; //导入方法依赖的package包/类
public void showPopup(KeyEvent keyEvent) {
    if (isContextMenuOn()) {
        return;
    }
    Component component = keyEvent.getComponent();
    if (component instanceof JMenuItem && (!(component instanceof JMenu) || ((JMenu) component).isSelected())) {
        return;
    }
    Point point = new Point(component.getX() + component.getWidth() / 2, component.getY() + component.getHeight() / 2);
    showPopup(component, point);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:12,代码来源:ContextMenuHandler.java

示例14: getControlButtonsRectangle

import java.awt.Component; //导入方法依赖的package包/类
protected Rectangle getControlButtonsRectangle( Container parent ) {
    Component c = getControlButtons();
    return new Rectangle( parent.getWidth()-c.getWidth()-4, 4, c.getWidth(), c.getHeight() );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:WinClassicEditorTabDisplayerUI.java

示例15: show

import java.awt.Component; //导入方法依赖的package包/类
public void show(Component parent, Runnable runOnClose) {
    this.runOnClose = runOnClose;
    key2bookmark = new HashMap<Character, BookmarkInfo>(2 * 46, 0.5f);
    BookmarkManager lockedBookmarkManager = BookmarkManager.getLocked();
    try {
        // Open projects should have their bookmarks loaded before invocation of this method
        // so that it's possible to enumerate present keys properly
        for (ProjectBookmarks projectBookmarks : lockedBookmarkManager.activeProjectBookmarks()) {
            for (FileBookmarks fileBookmarks : projectBookmarks.getFileBookmarks()) {
                for (BookmarkInfo bookmark : fileBookmarks.getBookmarks()) {
                    String key = bookmark.getKey();
                    if (key != null && key.length() > 0) {
                        key2bookmark.put(key.charAt(0), bookmark);
                    }
                }
            }
        }
    } finally {
        lockedBookmarkManager.unlock();
    }
    
    JPanel cellPanel = new JPanel();
    if (key2bookmark.size() > 0) {
        cellPanel.setLayout(new GridLayout(4, 10, 2, 2));
        addCells(cellPanel, 10 * 4, '1', '9', '0', '0', 'A', 'Z');
    } else { // No bookmarks with keys
        cellPanel.setLayout(new GridLayout(2, 1, 2, 2));
        JLabel noKeysLabel = new JLabel(NbBundle.getMessage(BookmarkKeyChooser.class, "LBL_keyChooserNoActiveKeys"), JLabel.CENTER);
        JLabel noKeysHelpLabel = new JLabel(NbBundle.getMessage(BookmarkKeyChooser.class, "LBL_keyChooserNoActiveKeysHelp"), JLabel.CENTER);
        cellPanel.add(noKeysLabel);
        cellPanel.add(noKeysHelpLabel);
    }
    cellPanel.setBorder(new EmptyBorder(4, 4, 4, 4));
    closeButton = new JButton(NbBundle.getMessage(BookmarkKeyChooser.class, "CTL_keyChooserCloseButton")); // NOI18N

    dialog = org.netbeans.editor.DialogSupport.createDialog(
            NbBundle.getMessage(BookmarkKeyChooser.class, "CTL_keyChooserTitle"), // NOI18N
            cellPanel, true, // modal
            new JButton[] { closeButton }, false, // bottom buttons
            0, // defaultIndex = 0 => allow close by Enter key too
            0, // cancelIndex
            this // ActionListener
    );
    dialog.pack();
    
    Point parentMidPoint = new Point(parent.getWidth() / 2, parent.getHeight() / 2);
    SwingUtilities.convertPointToScreen(parentMidPoint, parent);
    dialog.setBounds(
            parentMidPoint.x - dialog.getWidth() / 2,
            parentMidPoint.y - dialog.getHeight() / 2,
            dialog.getWidth(),
            dialog.getHeight()
    );
    closeButton.addKeyListener(this);
    dialog.setAlwaysOnTop(true);
    dialog.setVisible(true);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:58,代码来源:BookmarkKeyChooser.java


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