【发布时间】:2012-08-18 12:42:47
【问题描述】:
目前我有这个JComboBox,我怎样才能让里面的内容居中?
String[] strs = new String[]{"15158133110", "15158133124", "15158133458"};
JComboBox com = new JComboBox(strs);
【问题讨论】:
标签: java swing center jcombobox cellrenderer
目前我有这个JComboBox,我怎样才能让里面的内容居中?
String[] strs = new String[]{"15158133110", "15158133124", "15158133458"};
JComboBox com = new JComboBox(strs);
【问题讨论】:
标签: java swing center jcombobox cellrenderer
你需要创建一个 Renderer 然后将它应用到 JComboBox
DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
com.setRenderer(dlcr);
也导入这个,
import javax.swing.DefaultListCellRenderer;
【讨论】:
((JLabel)jComboBox1.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
试试这个
【讨论】: