How to focus items in a Java combo box
•
Java
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
二维码
