我們如何在 Java 中停用 JComboBox 箭頭按鈕?


是的,可以透過 `removeArrow()` 方法來實現。

以下是一個停用 JComboBox 箭頭按鈕的示例

示例

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);
         }
      }
   }
}

輸出

更新日期:2019 年 7 月 30 日

504 次瀏覽

開啟您的 職業生涯

透過完成課程獲取認證

開始
廣告
© . All rights reserved.