Is there a method for combobox in Java that will center elements in combobox? I tried this, but this did not work:
myCombobox.setAlignmentY(CENTER_ALIGNMENT);
Thank!
Try this link: How to use combo boxes (Java ™ Tutorials> Creating a GUI Using JFC / Swing> Using Swing Components)
class ComboBoxRenderer extends JLabel implements ListCellRenderer { public ComboBoxRenderer() { setOpaque(true); setHorizontalAlignment(CENTER); setVerticalAlignment(CENTER); } //. . .
or
((JLabel)comboBox.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
Have you considered the concept Renderersdescribed in JTable textbook pages oracles , teak concept - is similair to JComboBox, JList, JTableand JTree, in Rendereryou can center the desired text
Renderers
JComboBox
JList
JTable
JTree
Renderer