现在在做一个项目,看JComboBox的倒三角图标很难看,能把它换一个图片么。
如何实现呢....

解决方案 »

  1.   

    改变整个Swing的风格或许可以实现
      

  2.   

    难看?呵呵,许是我看多了,没感觉了吧。
    如果要改这个button,需要你更改BasicComboboxUI里面的东西。
    源码声明如下:
     // The arrow button that invokes the popup.
        protected JButton   arrowButton;而实现的时候
    protected void installComponents() {
            arrowButton = createArrowButton();
            comboBox.add( arrowButton );
            ……
            ……你可以看一下createArrowButton的实现:protected JButton createArrowButton() {
            JButton button = new BasicArrowButton(BasicArrowButton.SOUTH,
        UIManager.getColor("ComboBox.buttonBackground"),
        UIManager.getColor("ComboBox.buttonShadow"),
        UIManager.getColor("ComboBox.buttonDarkShadow"),
        UIManager.getColor("ComboBox.buttonHighlight"));
            button.setName("ComboBox.arrowButton");
            return button;
        }如果你有兴趣可以参考BasicArrowButton的类。但是如果你只是要改箭头方向的话,就不必了。默认的是
    BasicArrowButton.SOUTH。可以有EAST,WEST,NORTH,都是SwingConstants中的常量。
    如果要换个按钮,那你自己去定义,设置图标。
    说到这了已经,那该怎么做,你应该很清楚了吧?