关于JComboBox的一个问题,一直没有解决,希望大家能帮我一下。我这有我目前的代码,希望能帮我修改一下我的代码,实现我附件里要实现的效果,谢谢大家!!!我目前的代码:
import java.awt.*;
import javax.swing.*;public class TestJComboBox {
JFrame f = null;
JPanel panel = null;
JLabel label = null;
JComboBox box = null;
public TestJComboBox()
{
f = new JFrame();
Container container = f.getContentPane();
label = new JLabel("资金性质:");
box = new JComboBox();
box.setPreferredSize(new Dimension(190,20));
box.setEditable(true);
panel = new JPanel();
panel.add(label);
panel.add(box);
container.add(panel);
f.setVisible(true);
f.pack();
f.setSize(300,300);
} public static void main(String agrs[])
{
new TestJComboBox();
}
}
其实目的就是想要把JComboBox中的下拉框中的下拉箭头换成我自己的图标,然后我点我自己的图标后就可以选择相关的信息了。我该怎么做呢,我目前的效果的代码我放在这个贴子上,希望高手门帮我解决一下,最好能把我的代码修改了,实现我想要的效果,谢谢了。目前附件我传不上来,希望大家能看明白我的意思!!!
import java.awt.*;
import javax.swing.*;public class TestJComboBox {
JFrame f = null;
JPanel panel = null;
JLabel label = null;
JComboBox box = null;
public TestJComboBox()
{
f = new JFrame();
Container container = f.getContentPane();
label = new JLabel("资金性质:");
box = new JComboBox();
box.setPreferredSize(new Dimension(190,20));
box.setEditable(true);
panel = new JPanel();
panel.add(label);
panel.add(box);
container.add(panel);
f.setVisible(true);
f.pack();
f.setSize(300,300);
} public static void main(String agrs[])
{
new TestJComboBox();
}
}
其实目的就是想要把JComboBox中的下拉框中的下拉箭头换成我自己的图标,然后我点我自己的图标后就可以选择相关的信息了。我该怎么做呢,我目前的效果的代码我放在这个贴子上,希望高手门帮我解决一下,最好能把我的代码修改了,实现我想要的效果,谢谢了。目前附件我传不上来,希望大家能看明白我的意思!!!
public S2() {
Container container = this.getContentPane();
JLabel label = new JLabel("asddsasda:");
TestComboBox box = new TestComboBox();
box.setPreferredSize(new Dimension(190, 20));
box.setEditable(true);
JPanel panel = new JPanel();
panel.add(label);
panel.add(box); container.add(panel);
} public static void main(String agrs[]) {
S2 f = new S2(); f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setSize(300, 300);
} @SuppressWarnings("serial")
public class TestComboBox extends JComboBox {
public TestComboBox() {
super();
} @Override
public void setUI(ComboBoxUI ui) { super.setUI(new TestComboBoxUI());
} private class TestComboBoxUI extends BasicComboBoxUI {
@Override
protected JButton createArrowButton() {
JButton button =new JButton();
button.setName("ComboBox.arrowButton");
button.setIcon(new ImageIcon("src/test/java/pde0010016.gif"));
return button;
}
} }}