Is there a method for a combobox in Java that will center the items in the combobox? I tried this but it didn't work:
myCombobox.setAlignmentY(CENTER_ALIGNMENT);
Thanks!
Try this link: How to Use Combo Boxes (The Java™ Tutorials > Creating a GUI With 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);
You have look at Renderers concept, described about in the JTable tutorial on Oracles pages, thic concept is similair for JComboBox, JList, JTable and JTree, in the Renderer you can centering desired text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With