9

Currently I have this JComboBox, how can I get to center the content inside it?

String[] strs = new String[]{"15158133110", "15158133124", "15158133458"};
JComboBox com = new JComboBox(strs);
mKorbel
  • 109,525
  • 20
  • 134
  • 319
SUN XIAOYU
  • 93
  • 1
  • 3

2 Answers2

14

You need to create a Renderer then apply it to the JComboBox

DefaultListCellRenderer dlcr = new DefaultListCellRenderer(); 
dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER); 
com.setRenderer(dlcr); 

also import this,

import javax.swing.DefaultListCellRenderer; 
Sean F
  • 2,352
  • 3
  • 28
  • 40
1
((JLabel)jComboBox1.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);

Try This

Shinwar ismail
  • 299
  • 2
  • 9