Can we disable JComboBox arrow button in Java?


Yes, we can do that using removeArrow() method.

The following is an example to disable JComboBox arrow button:

Example

import java.awt.Component;
import java.awt.Container;
import javax.swing.*;
public class SwingDemo {
   public static void main(String[] args) {
      String[] strValues = {"One", "Two"};
      JComboBox<String> comboBox = new JComboBox<String>(strValues);
      removeArrow(comboBox);
      JOptionPane.showMessageDialog(null, comboBox);
   }
   private static void removeArrow(Container container) {
      Component[] c = container.getComponents();
      for (Component res : c) {
         if (res instanceof AbstractButton) {
            container.remove(res);
         }
      }
   }
}

Output

Updated on: 30-Jul-2019

376 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements