hi
my problem is that i want to show some information about button when clicked on that button but that information must be displayed below that button so and in the same menu
so for that what used i am think about popmenu is this right

Dani AI

Generated

: what you want is the typical auto-suggest/dropdown pattern (like Google Search) rather than a static label. 's idea of showing a JLabel can work for fixed help text, but for live suggestions use either an editable JComboBox (quick) or a JPopupMenu that holds a JList (more control over rendering and keyboard handling).

Basic approach:

  • Listen to the text field with a DocumentListener (or key listener) and compute matches.
  • If matching is expensive, run the search off the EDT (use SwingWorker) and update the UI on the EDT.
  • Update the JList model and call popup.show(textField, 0, textField.getHeight()) to display it directly under the field.
  • Hide the popup on focus lost, ESC, empty results, or after selection. Implement Up/Down/Enter handling so keyboard works like a real suggestion list.

Example skeleton (conceptual):

JPopupMenu popup = new JPopupMenu();
JList<String> list = new JList<>();
popup.add(new JScrollPane(list));

textField.getDocument().addDocumentListener(new DocumentListener() {
  void update() {
    List<String> matches = findMatches(textField.getText()); // do heavy work off EDT
    if (matches.isEmpty()) popup.setVisible(false);
    else {
      list.setListData(matches.toArray(new String[0]));
      popup.show(textField, 0, textField.getHeight());
    }
  }
  public void insertUpdate(DocumentEvent e) { update(); }
  public void removeUpdate(DocumentEvent e) { update(); }
  public void changedUpdate(DocumentEvent e) { update(); }
});

For production, consider libraries like GlazedLists or SwingX AutoCompleteDecorator to avoid reinventing filtering, keyboard handling and focus edge cases. See the Swing JPopupMenu API and the ComboBox tutorial for built-in options: JPopupMenu API and How to Use Combo Boxes.

Recommended Answers

All 2 Replies

Im not sure if i understood you correctly but you can make a JLabel under the button and when the button is clicked, the JLabel will be set to visible with the informations of a button on it.

similarr to google search editor when we right something in it .it produce tha drop downliast and give sugeestion

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.