Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox displaying Right Aligned Text  RSS feed

 
Daniel Puryear
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone out there configured a JComboBox for right aligned text in the JTextField and the PopUpMenu?? I thought I had written one some years ago
but can't seem to find it. Checking the 1.4, it still does not have a
'setHorizontalAlignment(<RIGHT> '
Tx
- Daniel P
 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you know, Swing implements M-V-C Model. So the methods you know in the past are distributed among its Model and supportive classes. Now setHorizontalAlignment is in ListCellRenderer. Write your own class extending it, and call setRenderer() on JComboBox.
 
Daniel Puryear
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, actually, I don't believe you'll find setHorizontalAlignment as a requirement in the ListCellRenderer interface or the DefaultListCellRenderer implementation. But, yes, if you write your own renderer that implements the ListCellRenderer, e.g provide the getListCellRendererComponent() callback for the JComboBox, then register the renderer with the JComboBox, it will use your new renderer. Then, of course, you can base your new renderer on something like JLabel, which DOES have a setHorizontalAlignment.
I found my family of renderers that I originally had completed for a JTable application - Thanks, Dan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!