本文整理匯總了Java中javax.swing.JComboBox.isPopupVisible方法的典型用法代碼示例。如果您正苦於以下問題:Java JComboBox.isPopupVisible方法的具體用法?Java JComboBox.isPopupVisible怎麽用?Java JComboBox.isPopupVisible使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JComboBox
的用法示例。
在下文中一共展示了JComboBox.isPopupVisible方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: init
import javax.swing.JComboBox; //導入方法依賴的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();
}
示例2: accept
import javax.swing.JComboBox; //導入方法依賴的package包/類
@Override
public boolean accept(Object sender) {
ACTION_ACCEPTED_CALLS++;
if (sender instanceof JComboBox) {
JComboBox c = (JComboBox) sender;
return !c.isPopupVisible();
}
return false;
}