目前我有这个JComboBox
,我怎样才能让里面的内容居中?
String[] strs = new String[]{"15158133110", "15158133124", "15158133458"};
JComboBox com = new JComboBox(strs);
目前我有这个JComboBox
,我怎样才能让里面的内容居中?
String[] strs = new String[]{"15158133110", "15158133124", "15158133458"};
JComboBox com = new JComboBox(strs);
您需要创建一个渲染器,然后将其应用到 JComboBox
DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
com.setRenderer(dlcr);
也导入这个,
import javax.swing.DefaultListCellRenderer;
((JLabel)jComboBox1.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
试试这个