Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4007272
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:36:46+00:00 2026-05-20T08:36:46+00:00

I try to attach action Events on the JCombobox arrow JButton. So I make

  • 0

I try to attach action Events on the JCombobox arrow JButton.

So I make a custom ComboBoxUI:

public class CustomBasicComboBoxUI extends BasicComboBoxUI {

    public static CustomBasicComboBoxUI createUI(JComponent c) {
        return new CustomBasicComboBoxUI ();
    }

    @Override
    protected JButton createArrowButton() {
        JButton button=super.createArrowButton();
        if(button!=null) {
            button.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    // arrow button clicked
                }
            });
        }
        return button;
    }
}

The problem with this is that the look of combobox is different, seem to be an old look.
Why? I only add a listener to the same arrow button…

Thank.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:36:47+00:00Added an answer on May 20, 2026 at 8:36 am

    Perhaps the problem is due to your expecting a JComboBox isn’t a BasicComboBoxUI but one of another look and feel, perhaps a MetalComboBoxUI.

    Rather than create a new CustomBasicComboBoxUI object, could you extract the JButton component from an existing JComboBox object? i.e.,

    import java.awt.Component;
    import java.awt.Container;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.*;
    
    public class ComboBoxArrowListener {
       private static void createAndShowUI() {
          String[] data = {"One", "Two", "Three"};
          JComboBox combo = new JComboBox(data);
          JPanel panel = new JPanel();
          panel.add(combo);
    
          JButton arrowBtn = getButtonSubComponent(combo);
          if (arrowBtn != null) {
             arrowBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                   System.out.println("arrow button pressed");
                }
             });
          }
    
          JFrame frame = new JFrame("ComboBoxArrowListener");
          frame.getContentPane().add(panel);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       private static JButton getButtonSubComponent(Container container) {
          if (container instanceof JButton) {
             return (JButton) container;
          } else {
             Component[] components = container.getComponents();
             for (Component component : components) {
                if (component instanceof Container) {
                   return getButtonSubComponent((Container)component);
                }
             }
          }
          return null;
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a little problem when i try to attach a class to an
Try as I might I cannot get my head around what the IteratorIterator class
when I try to attach a file to an email, I get a java.io.FileNotFoundException:
when i try to attach entity to context i get an exception An object
When I try to attach a .mdf file in Management Studio to open it
When I manually start Firefox and then try to attach to it using Browser.AttachTo(Find.First())
I'm getting this message when I try and attach to process. How do I
I noticed that every time I try to attach a file to a SharePoint
In my database application, when I try to attach a page to a site,
try { // CompareRecord record = new CompareRecord(); Connection conn = new CompareRecord().getConection(eliteddaprd,eliteddaprd,192.168.14.104,1521); ResultSet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.