English 中文(简体)
JComboBox在设定习俗后失去键盘事件
原标题:JComboBox loses keyboard events after setting custom UI

我有以下问题:

我需要为<代码>JComboBoxComponent设定一个海关编码。 (修改颜色、arrow等) 目前,我是在一位建筑商做这件事的:

public MyComboBox() {
   setUI(new MyComboBoxUI);
}

问题在于,在以这种方式确定国际交易日志之后,我在某种程度上放松了所有<条码>。 com博箱内填满的目录内容,即用arrow子打上滚动清单。

我在这里做了什么错误?

该法典:

public class CurrencyPairComboBox extends JComboBox { 

    public CurrencyPairComboBox() {
        setUI(new CurrencyPairComboBoxUI());
    }
}

class CurrencyPairComboBoxUI extends BasicComboBoxUI {

    @Override
    public void installUI(JComponent c) {
       super.installUI(c);

       listBox.setSelectionBackground(Color.BLACK);
       listBox.setSelectionForeground(Color.WHITE);
    }

    @Override
    protected JButton createArrowButton() {
       arrowButton = new JButton();
       arrowButton.setIcon(OrderWidgetUIConstants.DROPDOWN_ARROW_ICON);
       arrowButton.setRolloverIcon(OrderWidgetUIConstants.DROPDOWN_ARROW_HOVER_ICON);
       return arrowButton;
    }    
}
问题回答

我尝试了你在这里登出的法典,我看不到任何关键板问题,所有工作都是我预期的。

“entergraph “entergraph

import java.awt.*;
import javax.swing.*;

class ComboBoxTest extends JFrame {

    private static final long serialVersionUID = 1L;
    private JComboBox comboBox;
    private ImageIcon infoIcon = (ImageIcon) UIManager.getIcon("OptionPane.informationIcon");
    private ImageIcon warnIcon = (ImageIcon) UIManager.getIcon("OptionPane.warningIcon");

    ComboBoxTest() {
        String[] items = {"Item1", "Item2"};
        comboBox = new JComboBox(items);
        Container c = getContentPane();
        c.setLayout(new FlowLayout());
        c.add(comboBox);
        comboBox.setUI(new MyUI());
    }

    public JFrame getCurrentInstance() {
        return this;
    }

    public static void main(String[] args) {
        ComboBoxTest frame = new ComboBoxTest();
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.pack();
        frame.setVisible(true);
    }

    class MyUI extends javax.swing.plaf.basic.BasicComboBoxUI {

        @Override
        protected JButton createArrowButton() {
            JButton btn = new JButton();
            btn.setIcon(infoIcon);
            btn.setRolloverIcon(warnIcon);
            return btn;
        }
    }
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签