本文整理匯總了Java中java.awt.Frame.validate方法的典型用法代碼示例。如果您正苦於以下問題:Java Frame.validate方法的具體用法?Java Frame.validate怎麽用?Java Frame.validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Frame
的用法示例。
在下文中一共展示了Frame.validate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(final String[] args) throws HeadlessException {
final Frame frame = new Frame("Test Frame");
final List list = new List();
frame.setSize(300, 200);
list.add(ITEM_NAME);
list.select(0);
frame.add(list);
frame.validate();
frame.setVisible(true);
sleep();
if (!ITEM_NAME.equals(list.getSelectedItem())) {
throw new RuntimeException("List item not selected item.");
}
list.removeAll();
frame.dispose();
}
示例2: init
import java.awt.Frame; //導入方法依賴的package包/類
/**
* Test fails if it throws any exception.
*
* @throws Exception
*/
private void init() throws Exception {
if (!System.getProperty("os.name").startsWith("Windows")) {
System.out.println("This is Windows only test.");
return;
}
final Frame frame = new Frame("AWT Frame");
frame.pack();
frame.setSize(200, 200);
FramePeer frame_peer = AWTAccessor.getComponentAccessor()
.getPeer(frame);
Class comp_peer_class
= Class.forName("sun.awt.windows.WComponentPeer");
Field hwnd_field = comp_peer_class.getDeclaredField("hwnd");
hwnd_field.setAccessible(true);
long hwnd = hwnd_field.getLong(frame_peer);
Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame");
Constructor constructor
= clazz.getConstructor(new Class[]{long.class});
final Frame embedded_frame
= (Frame) constructor.newInstance(new Object[]{
new Long(hwnd)});;
final JComboBox<String> combo = new JComboBox<>(new String[]{
"Item 1", "Item 2"
});
combo.setSelectedIndex(1);
final Panel p = new Panel();
p.setLayout(new BorderLayout());
embedded_frame.add(p, BorderLayout.CENTER);
embedded_frame.validate();
p.add(combo);
p.validate();
frame.setVisible(true);
Robot robot = new Robot();
robot.delay(2000);
Rectangle clos = new Rectangle(
combo.getLocationOnScreen(), combo.getSize());
robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height / 2);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(1000);
if (!combo.isPopupVisible()) {
throw new RuntimeException("Combobox popup is not visible!");
}
robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height + 3);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(1000);
if (combo.getSelectedIndex() != 0) {
throw new RuntimeException("Combobox selection has not changed!");
}
embedded_frame.remove(p);
embedded_frame.dispose();
frame.dispose();
}