本文整理汇总了Java中java.awt.Component.getX方法的典型用法代码示例。如果您正苦于以下问题:Java Component.getX方法的具体用法?Java Component.getX怎么用?Java Component.getX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Component
的用法示例。
在下文中一共展示了Component.getX方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTextOffset
import java.awt.Component; //导入方法依赖的package包/类
/**
* Returns offset for the text.
* BasicMenuItemUI sets max text offset on the JPopupMenuUI.
* @param c PopupMenu to return text offset for.
* @return text offset for the component
*/
static int getTextOffset(JComponent c) {
int rv = -1;
Object maxTextOffset =
c.getClientProperty(BASICMENUITEMUI_MAX_TEXT_OFFSET);
if (maxTextOffset instanceof Integer) {
/*
* this is in JMenuItem coordinates.
* Let's assume all the JMenuItem have the same offset along X.
*/
rv = (Integer) maxTextOffset;
int menuItemOffset = 0;
Component component = c.getComponent(0);
if (component != null) {
menuItemOffset = component.getX();
}
rv += menuItemOffset;
}
return rv;
}
示例2: contains
import java.awt.Component; //导入方法依赖的package包/类
/**
* Returns true if selectio contains a component
*
* @param component
* @return boolean
*/
public boolean contains(Component component) {
int x = component.getX() - getX();
int y = component.getY() - getY();
return contains(x, y)
|| contains(x + component.getWidth(), y)
|| contains(x, y + component.getHeight())
|| contains(x + component.getWidth(), y + component.getHeight());
}
示例3: drawOpenSpotAtEndOfMenuBar
import java.awt.Component; //导入方法依赖的package包/类
private void drawOpenSpotAtEndOfMenuBar(Graphics2D g2, JComponent mb) {
Point mblocation = SwingUtilities.convertPoint(mb, new Point(0,0), this);
if(mb.getComponentCount() > 0) {
Component lastComp = mb.getComponent(mb.getComponentCount()-1);
mblocation.x += lastComp.getX() + lastComp.getWidth();
}
g2.drawRect(mblocation.x+2, mblocation.y+2, mb.getHeight()-4, mb.getHeight()-4);
}
示例4: 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);
}
示例5: 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();
}
示例6: mousePressed
import java.awt.Component; //导入方法依赖的package包/类
@Override
public void mousePressed(MouseEvent e) {
dragged = (Component) e.getSource();
relativePosition = new Point(dragged.getX(), dragged.getY());
relativePosition.translate(-e.getLocationOnScreen().x, -e.getLocationOnScreen().y);
}