8290399: [macos] Aqua LAF does not fire an action event if combo box … · openjdk/jdk11u-dev@05bb69d (original) (raw)

``

1

`+

/*

`

``

2

`+

`

``

3

`+

`

``

4

`+

`

``

5

`+

`

``

6

`+

`

``

7

`+

`

``

8

`+

`

``

9

`+

`

``

10

`+

`

``

11

`+

`

``

12

`+

`

``

13

`+

`

``

14

`+

`

``

15

`+

`

``

16

`+

`

``

17

`+

`

``

18

`+

`

``

19

`+

`

``

20

`+

`

``

21

`+

`

``

22

`+

*/

`

``

23

+

``

24

`+

/*

`

``

25

`+

`

``

26

`+

`

``

27

`+

`

``

28

`+

`

``

29

`+

`

``

30

`+

`

``

31

`+

`

``

32

`+

*/

`

``

33

+

``

34

`+

import java.awt.FlowLayout;

`

``

35

+

``

36

`+

import javax.swing.JComboBox;

`

``

37

`+

import javax.swing.JFrame;

`

``

38

`+

import javax.swing.JLabel;

`

``

39

`+

import javax.swing.JOptionPane;

`

``

40

`+

import javax.swing.JPanel;

`

``

41

`+

import javax.swing.SwingUtilities;

`

``

42

`+

import javax.swing.UIManager;

`

``

43

+

``

44

`+

public class JComboBoxActionEvent {

`

``

45

`+

private static final String instructionsText = " Click the arrow to display the menu.\n" +

`

``

46

`+

"While the menu is displayed, edit the text to create a new value.\n" +

`

``

47

`+

"Type return.\n" +

`

``

48

`+

"If a dialog appears with "ActionCommand received"\n" +

`

``

49

`+

"press Pass, else Fail";

`

``

50

+

``

51

`+

private static JFrame frame;

`

``

52

+

``

53

`+

public static void createAndShowGUI() throws Exception {

`

``

54

`+

SwingUtilities.invokeAndWait(() -> {

`

``

55

+

``

56

`+

JComboBox comboBox = new JComboBox<>(new String[]

`

``

57

`+

{ "Apple", "Orange", "Pear" });

`

``

58

`+

comboBox.setEditable(true);

`

``

59

`+

comboBox.addActionListener(e -> {

`

``

60

`+

System.out.println("Action Listener called: " + e.getActionCommand());

`

``

61

`+

if (e.getActionCommand().contains("comboBoxEdited")) {

`

``

62

`+

JOptionPane.showMessageDialog(null, "ActionCommand received");

`

``

63

`+

}

`

``

64

`+

});

`

``

65

+

``

66

`+

FlowLayout layout = new FlowLayout();

`

``

67

`+

JPanel panel = new JPanel(layout);

`

``

68

`+

panel.add(comboBox);

`

``

69

`+

frame = new JFrame("Test Editable Combo Box");

`

``

70

`+

frame.getContentPane().add(panel);

`

``

71

`+

frame.setVisible(true);

`

``

72

`+

frame.pack();

`

``

73

`+

frame.setLocationRelativeTo(null);

`

``

74

+

``

75

`+

PassFailJFrame.addTestWindow(frame);

`

``

76

`+

PassFailJFrame.positionTestWindow(frame,

`

``

77

`+

PassFailJFrame.Position.HORIZONTAL);

`

``

78

`+

});

`

``

79

`+

}

`

``

80

+

``

81

`+

public static void main(String[] args) throws Exception {

`

``

82

+

``

83

`+

UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");

`

``

84

+

``

85

`+

PassFailJFrame pfjFrame = new PassFailJFrame("JScrollPane "

`

``

86

`+

`

``

87

+

``

88

`+

createAndShowGUI();

`

``

89

+

``

90

`+

pfjFrame.awaitAndCheck();

`

``

91

`+

}

`

``

92

`+

}

`