Search in sources :

Example 1 with BasicComboPopup

use of javax.swing.plaf.basic.BasicComboPopup in project jdk8u_jdk by JetBrains.

the class bug7158712 method main.

public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(500);
    SynthLookAndFeel laf = new SynthLookAndFeel();
    laf.load(new ByteArrayInputStream(SYNTH_XML.getBytes("UTF8")), bug7158712.class);
    UIManager.setLookAndFeel(laf);
    EventQueue.invokeAndWait(new Runnable() {

        public void run() {
            comboBox = new JComboBox<>(new String[] { "Very Looooooooooooooooooooong Text Item 1", "Item 2" });
            JFrame frame = new JFrame();
            frame.add(comboBox, BorderLayout.NORTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(new Dimension(400, 300));
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
    Point comboBoxLocation = Util.invokeOnEDT(new Callable<Point>() {

        @Override
        public Point call() throws Exception {
            return comboBox.getLocationOnScreen();
        }
    });
    robot.mouseMove(comboBoxLocation.x, comboBoxLocation.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            BasicComboPopup popup = (BasicComboPopup) comboBox.getAccessibleContext().getAccessibleChild(0);
            Point popupPoint = popup.getLocationOnScreen();
            Point comboBoxPoint = comboBox.getLocationOnScreen();
            if (comboBoxPoint.x - 5 != popupPoint.x || comboBoxPoint.y + comboBox.getHeight() - 5 != popupPoint.y) {
                throw new RuntimeException("Invalid popup coordinates. Popup location: " + popupPoint + ", comboBox location: " + comboBoxPoint);
            }
            System.out.println("Test bug7158712 passed");
        }
    });
}
Also used : SynthLookAndFeel(javax.swing.plaf.synth.SynthLookAndFeel) SunToolkit(sun.awt.SunToolkit) ByteArrayInputStream(java.io.ByteArrayInputStream) BasicComboPopup(javax.swing.plaf.basic.BasicComboPopup)

Example 2 with BasicComboPopup

use of javax.swing.plaf.basic.BasicComboPopup in project knime-core by knime.

the class NodeDialogPane method noLightWeight.

/*
     * Converts the specified and all its parent Component object to no-light
     * weight components if they are of type JComboBox, JPopupMenu, or
     * BasicComboPopup.
     */
private static void noLightWeight(final Component c) {
    if (c instanceof Container) {
        if (c instanceof JComboBox) {
            JComboBox cb = (JComboBox) c;
            cb.setLightWeightPopupEnabled(false);
        }
        if (c instanceof JPopupMenu) {
            JPopupMenu pm = (JPopupMenu) c;
            pm.setLightWeightPopupEnabled(false);
        }
        if (c instanceof BasicComboPopup) {
            BasicComboPopup cp = (BasicComboPopup) c;
            cp.setLightWeightPopupEnabled(false);
        }
        Container o = (Container) c;
        for (int cnt = o.getComponentCount(); --cnt >= 0; ) {
            Component newComponent = o.getComponent(cnt);
            noLightWeight(newComponent);
        }
    }
}
Also used : NodeContainer(org.knime.core.node.workflow.NodeContainer) Container(java.awt.Container) JComboBox(javax.swing.JComboBox) Component(java.awt.Component) JComponent(javax.swing.JComponent) BasicComboPopup(javax.swing.plaf.basic.BasicComboPopup) JPopupMenu(javax.swing.JPopupMenu)

Example 3 with BasicComboPopup

use of javax.swing.plaf.basic.BasicComboPopup in project otapij by FellowTraveler.

the class SteppedComboBox method createPopup.

protected ComboPopup createPopup() {
    BasicComboPopup popup = new BasicComboPopup(comboBox) {

        @Override
        public void show() {
            Dimension popupSize = ((SteppedComboBox) comboBox).getPopupSize();
            popupSize.setSize(popupSize.width, getPopupHeightForRowCount(comboBox.getMaximumRowCount()));
            Rectangle popupBounds = computePopupBounds(0, comboBox.getBounds().height, popupSize.width, popupSize.height);
            scroller.setMaximumSize(popupBounds.getSize());
            scroller.setPreferredSize(popupBounds.getSize());
            scroller.setMinimumSize(popupBounds.getSize());
            list.invalidate();
            int selectedIndex = comboBox.getSelectedIndex();
            if (selectedIndex == -1) {
                list.clearSelection();
            } else {
                list.setSelectedIndex(selectedIndex);
            }
            list.ensureIndexIsVisible(list.getSelectedIndex());
            setLightWeightPopupEnabled(comboBox.isLightWeightPopupEnabled());
            show(comboBox, popupBounds.x, popupBounds.y);
        }
    };
    popup.getAccessibleContext().setAccessibleParent(comboBox);
    return popup;
}
Also used : Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) BasicComboPopup(javax.swing.plaf.basic.BasicComboPopup)

Aggregations

BasicComboPopup (javax.swing.plaf.basic.BasicComboPopup)3 Component (java.awt.Component)1 Container (java.awt.Container)1 Dimension (java.awt.Dimension)1 Rectangle (java.awt.Rectangle)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 JComboBox (javax.swing.JComboBox)1 JComponent (javax.swing.JComponent)1 JPopupMenu (javax.swing.JPopupMenu)1 SynthLookAndFeel (javax.swing.plaf.synth.SynthLookAndFeel)1 NodeContainer (org.knime.core.node.workflow.NodeContainer)1 SunToolkit (sun.awt.SunToolkit)1