本文整理汇总了Java中java.awt.Window.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Window.getWidth方法的具体用法?Java Window.getWidth怎么用?Java Window.getWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Window
的用法示例。
在下文中一共展示了Window.getWidth方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import java.awt.Window; //导入方法依赖的package包/类
private static void test(GraphicsConfiguration gc) throws AWTException {
final Window frame = new Frame(gc);
try {
frame.addMouseWheelListener(e -> {
wheelX = e.getXOnScreen();
wheelY = e.getYOnScreen();
done = true;
});
frame.setSize(300, 300);
frame.setVisible(true);
final Robot robot = new Robot();
robot.setAutoDelay(50);
robot.setAutoWaitForIdle(true);
mouseX = frame.getX() + frame.getWidth() / 2;
mouseY = frame.getY() + frame.getHeight() / 2;
robot.mouseMove(mouseX, mouseY);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseWheel(10);
validate();
} finally {
frame.dispose();
}
}
示例2: isButtonOnScreen
import java.awt.Window; //导入方法依赖的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;
}
}
示例3: addNotify
import java.awt.Window; //导入方法依赖的package包/类
/**
* Updates the font metrics the first time we're displayed.
*/
@Override
public void addNotify() {
super.addNotify();
// Some LookAndFeels (e.g. WebLaF) for some reason have a 0x0 parent
// window initially (perhaps something to do with them fading in?),
// which will cause an exception from getGraphics(), so we must be
// careful here.
if (metricsNeverRefreshed) {
Window parent = SwingUtilities.getWindowAncestor(this);
if (parent!=null && parent.getWidth()>0 && parent.getHeight()>0) {
refreshFontMetrics(getGraphics2D(getGraphics()));
metricsNeverRefreshed = false;
}
}
// Re-start parsing if we were removed from one container and added
// to another
if (parserManager!=null) {
parserManager.restartParsing();
}
}
示例4: calculatePosition
import java.awt.Window; //导入方法依赖的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);
}
示例5: mouseDragged
import java.awt.Window; //导入方法依赖的package包/类
@Override
public void mouseDragged(MouseEvent e) {
Point newPos = e.getPoint();
SwingUtilities.convertPointToScreen(newPos, SizeGrip.this);
int xDelta = newPos.x - origPos.x;
int yDelta = newPos.y - origPos.y;
Window wind = SwingUtilities.getWindowAncestor(SizeGrip.this);
if (wind!=null) { // Should always be true
if (getComponentOrientation().isLeftToRight()) {
int w = wind.getWidth();
if (newPos.x>=wind.getX()) {
w += xDelta;
}
int h = wind.getHeight();
if (newPos.y>=wind.getY()) {
h += yDelta;
}
wind.setSize(w,h);
}
else { // RTL
int newW = Math.max(1, wind.getWidth()-xDelta);
int newH = Math.max(1, wind.getHeight()+yDelta);
wind.setBounds(newPos.x, wind.getY(), newW, newH);
}
// invalidate()/validate() needed pre-1.6.
wind.invalidate();
wind.validate();
}
origPos.setLocation(newPos);
}
示例6: testWindowBounds
import java.awt.Window; //导入方法依赖的package包/类
private static void testWindowBounds(final DisplayMode dm, final Window w) {
if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) {
System.err.println(" Wrong window bounds:" +
" Expected: width = " + dm.getWidth()
+ ", height = " + dm.getHeight() + " Actual: "
+ w.getSize());
passed = false;
}
}