JComboBox的问题,可以让下拉出来的列表显示两列吗? 可以让JComboBox下拉出来的列表显示两列吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那位高手能帮帮俺,jComboBox的构造器有一个是带model参数的,是不是这个可以进行设置?不会是需要我继承JComponent再自己写个控件吧? import java.awt.*;import javax.swing.*;public class T { public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } JComboBox combobox = new JComboBox(); combobox.addItem(new String[] {"Good", "Morning"}); combobox.addItem(new String[] {"Good", "Afternoon"}); combobox.addItem(new String[] {"Good", "Night"}); combobox.setRenderer(new TwoColumnsRenderer()); JFrame f = new JFrame(); f.getContentPane().add(combobox, BorderLayout.CENTER); f.pack(); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }}class TwoColumnsRenderer extends JPanel implements ListCellRenderer { private DefaultListCellRenderer column1 = new DefaultListCellRenderer(); private DefaultListCellRenderer column2 = new DefaultListCellRenderer(); public TwoColumnsRenderer() { super(new GridLayout(1, 0, 1, 0)); add(column1); add(column2); } public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String array[] = (String[]) value; column1.getListCellRendererComponent(list, array[0], index, isSelected, cellHasFocus); column2.getListCellRendererComponent(list, array[1], index, isSelected, cellHasFocus); return this; }} 学生成绩的Excel表格以文本文件每行表示一个学生的成绩记录 filedialog对话框打开文件在textarea中的显示问题 一个普通的APPLET,导致IE闪烁!!! 请问怎么改变JEditorPane中文字的大小? 请教一个JBuilder7.0安装的问题,谢谢! 一个让人迷惑的问题! 一个傻问题?? 一些关于接口的问题 大虾救我!!! Java 类输出数据类型 精度的困惑 已知一个图片的URL,怎么在程序里把它取出来??为什么有时不行呢?? 在APPLET中,我使用URL资源,求命啊
不会是需要我继承JComponent再自己写个控件吧?
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
} JComboBox combobox = new JComboBox();
combobox.addItem(new String[] {"Good", "Morning"});
combobox.addItem(new String[] {"Good", "Afternoon"});
combobox.addItem(new String[] {"Good", "Night"});
combobox.setRenderer(new TwoColumnsRenderer()); JFrame f = new JFrame();
f.getContentPane().add(combobox, BorderLayout.CENTER);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}class TwoColumnsRenderer extends JPanel implements ListCellRenderer {
private DefaultListCellRenderer column1 = new DefaultListCellRenderer();
private DefaultListCellRenderer column2 = new DefaultListCellRenderer();
public TwoColumnsRenderer() {
super(new GridLayout(1, 0, 1, 0));
add(column1);
add(column2);
}
public Component getListCellRendererComponent(
JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
String array[] = (String[]) value;
column1.getListCellRendererComponent(list, array[0], index, isSelected, cellHasFocus);
column2.getListCellRendererComponent(list, array[1], index, isSelected, cellHasFocus); return this;
}
}