/** Alter the bounds of the popup just before it is made visible. */
  @Override
  public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
    JComboBox comboBox = (JComboBox) e.getSource();

    if (comboBox.getItemCount() == 0) return;

    final Object child = comboBox.getAccessibleContext().getAccessibleChild(0);

    if (child instanceof BasicComboPopup) {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              customizePopup((BasicComboPopup) child);
            }
          });
    }
  }
Example #2
0
  public PIDSelectPanel(JButton okButton) {
    this.okButton = okButton;

    combo = new JComboBox<>();
    button = new JButton(REFRESH_BUTTON_NAME);

    JPanel infoPanel = new JPanel();
    infoPanel.setLayout(new GridBagLayout());

    GridBagConstraints labelGbc = new GridBagConstraints();
    labelGbc.insets = new Insets(3, 5, 0, 0);
    labelGbc.anchor = WEST;

    GridBagConstraints valueGbc = new GridBagConstraints();
    valueGbc.weightx = 1.0;
    valueGbc.fill = HORIZONTAL;
    valueGbc.insets = new Insets(3, 5, 0, 5);
    valueGbc.gridwidth = REMAINDER;
    valueGbc.anchor = WEST;

    JLabel l;

    l = new JLabel(PID_LABEL_TEXT);
    l.setFont(l.getFont().deriveFont(BOLD));
    infoPanel.add(l, labelGbc);
    infoPanel.add(pidLabel = new JLabel(), valueGbc);
    l = new JLabel(MAIN_CLASS_LABEL_TEXT);
    l.setFont(l.getFont().deriveFont(BOLD));
    infoPanel.add(l, labelGbc);
    infoPanel.add(mainClassLabel = new JLabel(), valueGbc);
    l = new JLabel(ARGUMENTS_LABEL_TEXT);
    l.setFont(l.getFont().deriveFont(BOLD));
    infoPanel.add(l, labelGbc);
    infoPanel.add(argumentsLabel = new JLabel(), valueGbc);
    l = new JLabel(VM_ARGUMENTS_LABEL_TEXT);
    l.setFont(l.getFont().deriveFont(BOLD));
    infoPanel.add(l, labelGbc);
    infoPanel.add(vmArgumentsLabel = new JLabel(), valueGbc);
    l = new JLabel(VM_FLAGS_LABEL_TEXT);
    l.setFont(l.getFont().deriveFont(BOLD));
    infoPanel.add(l, labelGbc);
    infoPanel.add(vmFlagsLabel = new JLabel(), valueGbc);

    combo.setRenderer(new PIDComboRenderer());
    combo.getAccessibleContext().setAccessibleName(COMBO_ACCESS_NAME);
    combo.getAccessibleContext().setAccessibleDescription(COMBO_ACCESS_DESCR);

    button.getAccessibleContext().setAccessibleDescription(BUTTON_ACCESS_DESCR);

    setBorder(createEmptyBorder(12, 12, 12, 12));
    setLayout(new BorderLayout(0, 10));

    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BorderLayout(5, 0));

    northPanel.add(combo, CENTER);
    northPanel.add(button, EAST);

    add(northPanel, NORTH);
    add(infoPanel, CENTER);

    okButton.setEnabled(false);

    refreshCombo();

    button.addActionListener(this);
    combo.addActionListener(this);
  }