How to focus items in a Java combo box

Is there a way to center the items in the combo box in Java? I tried this, but it didn't work:

myCombo@R_793_2419@.setAlignmentY(CENTER_ALIGNMENT);

thank you!

Solution

Try this link: how to use combo boxes (the Java ™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

class Combo@R_793_2419@Renderer extends JLabel
                   implements ListCellRenderer {
  public Combo@R_793_2419@Renderer() {
    setOpaque(true);
    setHorizontalAlignment(CENTER);
    setVerticalAlignment(CENTER);
  }
  //. . .

or

((JLabel)combo@R_793_2419@.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>